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,7 +64,12 @@ const openDownloadDialog = (blob, fileName) => {
64 64
  */
65 65
 export const exportToExcel = (sheetListInfo, excelName) => {
66 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 73
     const sheet = XLSX2.utils.json_to_sheet(sheetItem.list);
69 74
     // 设置每个单元格的样式
70 75
     let range = XLSX.utils.decode_range(sheet["!ref"]);
@@ -78,8 +83,12 @@ export const exportToExcel = (sheetListInfo, excelName) => {
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 92
   const workbookBlob = workbook2blob(wb);
84 93
   // 导出最后的总表
85 94
   openDownloadDialog(workbookBlob, excelName + ".xlsx");

Loading…
Cancel
Save