Browse Source

设备导出优化

gzb
wangzhonglu 8 months ago
parent
commit
38558b9ef2
1 changed files with 12 additions and 3 deletions
  1. 12
    3
      src/utils/exportToExcel.js

+ 12
- 3
src/utils/exportToExcel.js View File

64
  */
64
  */
65
 export const exportToExcel = (sheetListInfo, excelName) => {
65
 export const exportToExcel = (sheetListInfo, excelName) => {
66
   const wb = XLSX2.utils.book_new();
66
   const wb = XLSX2.utils.book_new();
67
-  for (const sheetItem of sheetListInfo) {
67
+  sheetListInfo.forEach((sheetItem, sheetIndex) => {
68
+    sheetItem.list.forEach((item) => {
69
+      for (const key in item) {
70
+        item[key] = item[key] || "";
71
+      }
72
+    });
68
     const sheet = XLSX2.utils.json_to_sheet(sheetItem.list);
73
     const sheet = XLSX2.utils.json_to_sheet(sheetItem.list);
69
     // 设置每个单元格的样式
74
     // 设置每个单元格的样式
70
     let range = XLSX.utils.decode_range(sheet["!ref"]);
75
     let range = XLSX.utils.decode_range(sheet["!ref"]);
78
         }
83
         }
79
       }
84
       }
80
     }
85
     }
81
-    XLSX2.utils.book_append_sheet(wb, sheet, sheetItem.name);
82
-  }
86
+    XLSX2.utils.book_append_sheet(
87
+      wb,
88
+      sheet,
89
+      sheetItem.name || `sheet${sheetIndex + 1}`
90
+    );
91
+  });
83
   const workbookBlob = workbook2blob(wb);
92
   const workbookBlob = workbook2blob(wb);
84
   // 导出最后的总表
93
   // 导出最后的总表
85
   openDownloadDialog(workbookBlob, excelName + ".xlsx");
94
   openDownloadDialog(workbookBlob, excelName + ".xlsx");

Loading…
Cancel
Save