|
|
@@ -246,7 +246,7 @@
|
|
|
<el-table
|
|
|
style="width: 100%; height: 33vh"
|
|
|
:data="tableData1"
|
|
|
- row-key="ID"
|
|
|
+ row-key="ID" id="cjstable"
|
|
|
highlight-current-row
|
|
|
border
|
|
|
:row-class-name="rowClassName"
|
|
|
@@ -729,24 +729,95 @@ const pd_lcd_handleNodeClick = async(node) => {
|
|
|
console.log(getOrderProcessRight_list)
|
|
|
processList.value = getOrderProcessRight_list.data
|
|
|
}
|
|
|
-// 导出excel
|
|
|
+
|
|
|
const exportExcel = () => {
|
|
|
- const labels = tableCols1.map((item) => item.label)
|
|
|
- const props = tableCols1.map((item) => item.prop)
|
|
|
-
|
|
|
- const data = tableData1.value.map((item) => {
|
|
|
- const row = {}
|
|
|
- props.forEach((prop, index) => {
|
|
|
- row[labels[index]] = item?.[prop]
|
|
|
- })
|
|
|
- return row
|
|
|
- })
|
|
|
- if (data[0]?.[labels[0]] === undefined) {
|
|
|
- return
|
|
|
- }
|
|
|
- exportExcelFile(data)
|
|
|
-}
|
|
|
+ const el = document.getElementById('cjstable');
|
|
|
+ const filename = '超节损导出.xlsx';
|
|
|
+
|
|
|
+ // 1. 获取原始表格数据
|
|
|
+ const wb = XLSX.utils.table_to_book(el, { raw: true });
|
|
|
+ const ws = wb.Sheets[wb.SheetNames[0]];
|
|
|
+
|
|
|
+ // 2. 定义需要转换为数字的列(基于原始列字母)
|
|
|
+ const originalNumberColumns = {
|
|
|
+ 'C': 0, // 原C列 → 删除A列后变为B列
|
|
|
+ 'D': 2, // 原D列 → 删除A列后变为C列
|
|
|
+ 'G': 4, // 原G列 → 删除A列后变为F列
|
|
|
+ 'J': 0, // 原J列 → 删除A列后变为I列
|
|
|
+ 'M': 0, // 原M列 → 删除A列后变为L列
|
|
|
+ 'N': 2, // 原N列 → 删除A列后变为M列
|
|
|
+ 'O': 0, // 原O列 → 删除A列后变为N列
|
|
|
+ 'P': 0, // 原P列 → 删除A列后变为O列
|
|
|
+ 'Q': 0, // 原Q列 → 删除A列后变为P列
|
|
|
+ 'R': 0, // 原R列 → 删除A列后变为Q列
|
|
|
+ 'S': 0, // 原S列 → 删除A列后变为R列
|
|
|
+ 'T': 0, // 原T列 → 删除A列后变为S列
|
|
|
+ 'U': 0, // 原U列 → 删除A列后变为T列
|
|
|
+ 'V': 0, // 原V列 → 删除A列后变为U列
|
|
|
+ 'W': 0 // 原W列 → 删除A列后变为V列
|
|
|
+ };
|
|
|
+
|
|
|
+ // 3. 创建新工作表(左移后的数据)
|
|
|
+ const newWs = {};
|
|
|
+ const range = XLSX.utils.decode_range(ws['!ref']);
|
|
|
+
|
|
|
+ // 调整列范围(删除A列)
|
|
|
+ range.s.c = 0; // 从A列开始(原B列)
|
|
|
+ range.e.c -= 1; // 结束列减1
|
|
|
+ newWs['!ref'] = XLSX.utils.encode_range(range);
|
|
|
+
|
|
|
+ // 复制其他工作表属性(排除A列)
|
|
|
+ if (ws['!cols']) newWs['!cols'] = ws['!cols'].slice(1);
|
|
|
+ if (ws['!rows']) newWs['!rows'] = ws['!rows'];
|
|
|
+ if (ws['!merges']) newWs['!merges'] = ws['!merges'];
|
|
|
+
|
|
|
+ // 4. 左移所有列数据(A列→删除,B列→A列,C列→B列...)
|
|
|
+ Object.keys(ws).forEach(address => {
|
|
|
+ if (!address.startsWith('!')) {
|
|
|
+ const col = address.charAt(0);
|
|
|
+ const row = address.slice(1);
|
|
|
+
|
|
|
+ if (col !== 'A') { // 跳过A列
|
|
|
+ // 计算新列字母(左移一列)
|
|
|
+ const newCol = String.fromCharCode(col.charCodeAt(0) - 1);
|
|
|
+ const newAddress = newCol + row;
|
|
|
+
|
|
|
+ // 复制单元格数据
|
|
|
+ newWs[newAddress] = { ...ws[address] };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 5. 转换数字格式(基于左移后的列字母)
|
|
|
+ Object.keys(newWs).forEach(address => {
|
|
|
+ const col = address.charAt(0);
|
|
|
+ const originalCol = String.fromCharCode(col.charCodeAt(0));
|
|
|
+
|
|
|
+ if (originalNumberColumns[originalCol] !== undefined) {
|
|
|
+ const cell = newWs[address];
|
|
|
+ const num = parseFloat(cell.v);
|
|
|
+
|
|
|
+ if (!isNaN(num)) {
|
|
|
+ cell.t = 'n';
|
|
|
+ cell.v = num;
|
|
|
+ cell.z = originalNumberColumns[originalCol] === 0
|
|
|
+ ? '0'
|
|
|
+ : `0.${'0'.repeat(originalNumberColumns[originalCol])}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ // 6. 更新工作簿并导出
|
|
|
+ wb.Sheets[wb.SheetNames[0]] = newWs;
|
|
|
+ const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
|
|
|
+
|
|
|
+ try {
|
|
|
+ FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
|
|
|
+ } catch (e) {
|
|
|
+ console.error('导出失败:', e);
|
|
|
+ }
|
|
|
+ return wbout;
|
|
|
+};
|
|
|
|
|
|
//选择月份后显示表格数据
|
|
|
const cjsjetableData = reactive([]);
|
|
|
@@ -798,6 +869,28 @@ const exportToExcel = ()=>{
|
|
|
// 文件名
|
|
|
const filename = `员工超节损金额_${formattedDate}.xlsx`;
|
|
|
const wb = XLSX.utils.table_to_book(el, { raw: true });
|
|
|
+
|
|
|
+
|
|
|
+ // 获取第一个工作表
|
|
|
+ const ws = wb.Sheets[wb.SheetNames[0]];
|
|
|
+
|
|
|
+ // 遍历单元格,设置数字格式(设置从Excel列转化数字格式)
|
|
|
+ Object.keys(ws).forEach(address => {
|
|
|
+ if(!address.startsWith('!')) { // 跳过非单元格数据
|
|
|
+ if(address.startsWith('D')) {
|
|
|
+ const cell = ws[address];
|
|
|
+ // 尝试转换为数字
|
|
|
+ const num = parseFloat(cell.v);
|
|
|
+ if(!isNaN(num)) {
|
|
|
+ cell.t = 'n'; // 设置为数字类型
|
|
|
+ cell.v = num; // 更新值
|
|
|
+ cell.z = '0.00'; // 设置数字格式(可选)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
|
|
|
try {
|
|
|
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
|