@fe-free/file 1.4.17 → 1.4.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @ones-wb/file
2
2
 
3
+ ## 1.4.19
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: xlsx
8
+
9
+ ## 1.4.18
10
+
3
11
  ## 1.4.17
4
12
 
5
13
  ## 1.4.16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/file",
3
- "version": "1.4.17",
3
+ "version": "1.4.19",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -1,7 +1,7 @@
1
1
  import type { Cell, Workbook, Worksheet } from 'exceljs';
2
2
  import ExcelJS from 'exceljs';
3
3
  import FileSaver from 'file-saver';
4
- import { isNumber } from 'lodash-es';
4
+ import { isDate, isNumber } from 'lodash-es';
5
5
 
6
6
  type JSONSheetItem = {
7
7
  name: string;
@@ -62,6 +62,17 @@ function eachRowAndCell(worksheet: Worksheet, callback) {
62
62
  });
63
63
  }
64
64
 
65
+ function fixDate(cell: any) {
66
+ // excel 不保存时区。
67
+ // 假设 excel 显示的是 2025-06-06 12:00:00,那么 xlsx 获取到的是 Fri Jun 06 2025 20:00:00 GMT+0800 (中国标准时间)
68
+ // 所以需要把 xlsx 获取到的日期转成当前时区
69
+
70
+ const date = new Date(cell);
71
+ // 得到负数 -480
72
+ const offset = date.getTimezoneOffset();
73
+ return new Date(date.getTime() + offset * 60 * 1000);
74
+ }
75
+
65
76
  function worksheetToJSON(
66
77
  worksheet: Worksheet,
67
78
  processCell?: (info: { cell: Cell; colNumber: number; rowNumber: number }) => void,
@@ -77,7 +88,19 @@ function worksheetToJSON(
77
88
  });
78
89
 
79
90
  // 挪掉空行。 空行会显示 null
80
- return sheet.filter(Boolean);
91
+ let json = sheet.filter(Boolean);
92
+
93
+ json = json.map((row) => {
94
+ return row.map((cell) => {
95
+ if (isDate(cell)) {
96
+ return fixDate(cell);
97
+ } else {
98
+ return cell;
99
+ }
100
+ });
101
+ });
102
+
103
+ return json;
81
104
  }
82
105
 
83
106
  interface JSONToWorksheetOption {