bl-common-vue3 3.8.120 → 3.8.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bl-common-vue3",
3
- "version": "3.8.120",
3
+ "version": "3.8.121",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "description": "bailing vue3 common components lib",
@@ -316,18 +316,14 @@ export async function createWorkbook(
316
316
  const sourceJson = styledExportOptions.enabled
317
317
  ? json.map((item) => ({ ...item }))
318
318
  : null;
319
- //导出xlsx
320
- json.forEach((item) => {
321
- for (let i in item) {
322
- // eslint-disable-next-line no-prototype-builtins
323
- if (fields.hasOwnProperty(i)) {
324
- item[fields[i]] = item[i];
325
- }
326
- delete item[i]; //删除原先的对象属性
327
- }
328
- });
319
+ const fieldKeys = Object.keys(fields);
320
+ // 字段 key 必须保留到取值阶段;不同字段允许使用相同表头,不能用表头文案作为对象 key,否则后写入的同名列会丢失。
321
+ const sheetRows = [
322
+ Object.values(fields),
323
+ ...json.map((item) => fieldKeys.map((field) => item?.[field])),
324
+ ];
329
325
  let wb = XLSX.utils.book_new(); //工作簿对象包含一SheetNames数组,以及一个表对象映射表名称到表对象。XLSX.utils.book_new实用函数创建一个新的工作簿对象。
330
- let ws = XLSX.utils.json_to_sheet(json, { header: Object.values(fields) }); //将JS对象数组转换为工作表。
326
+ let ws = XLSX.utils.aoa_to_sheet(sheetRows); //按列顺序写入,允许不同字段展示相同的表头文案。
331
327
  if (merges.length) {
332
328
  ws["!merges"] = merges;
333
329
  }