read-excel-file 9.3.3 → 9.3.5
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 +9 -0
- package/README.md +32 -2
- package/browser/index.cjs +3 -0
- package/browser/index.d.ts +16 -0
- package/browser/index.js +4 -1
- package/bundle/read-excel-file.min.js +1 -1
- package/bundle/read-excel-file.min.js.map +1 -1
- package/commonjs/export/convertInputToNodeStream.js +0 -12
- package/commonjs/export/convertInputToNodeStream.js.map +1 -1
- package/commonjs/export/parseSheet.js +14 -7
- package/commonjs/export/parseSheet.js.map +1 -1
- package/commonjs/export/readSheetBrowser.js +3 -6
- package/commonjs/export/readSheetBrowser.js.map +1 -1
- package/commonjs/export/readSheetNode.js +3 -6
- package/commonjs/export/readSheetNode.js.map +1 -1
- package/commonjs/export/readSheetUniversal.js +2 -2
- package/commonjs/export/readSheetUniversal.js.map +1 -1
- package/commonjs/export/readSheetWebWorker.js +5 -5
- package/commonjs/export/readSheetWebWorker.js.map +1 -1
- package/commonjs/export/readXlsxFileBrowser.js +3 -6
- package/commonjs/export/readXlsxFileBrowser.js.map +1 -1
- package/commonjs/export/readXlsxFileNode.js +3 -6
- package/commonjs/export/readXlsxFileNode.js.map +1 -1
- package/commonjs/export/readXlsxFileUniversal.js +2 -2
- package/commonjs/export/readXlsxFileUniversal.js.map +1 -1
- package/commonjs/export/readXlsxFileWebWorker.js +5 -5
- package/commonjs/export/readXlsxFileWebWorker.js.map +1 -1
- package/commonjs/export/unpackXlsxFileBrowser.js +15 -4
- package/commonjs/export/unpackXlsxFileBrowser.js.map +1 -1
- package/commonjs/export/unpackXlsxFileBrowser.test.js.map +1 -0
- package/commonjs/export/unpackXlsxFileNode.js +32 -5
- package/commonjs/export/unpackXlsxFileNode.js.map +1 -1
- package/commonjs/export/unpackXlsxFileNode.test.js.map +1 -0
- package/commonjs/export/unpackXlsxFileUniversal.js +14 -3
- package/commonjs/export/unpackXlsxFileUniversal.js.map +1 -1
- package/commonjs/export/unpackXlsxFileUniversal.test.js.map +1 -0
- package/commonjs/parseSheetData/parseSheetData.js +9 -6
- package/commonjs/parseSheetData/parseSheetData.js.map +1 -1
- package/commonjs/saxen/parser.js +1 -1
- package/commonjs/saxen/parser.js.map +1 -1
- package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js +100 -0
- package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
- package/commonjs/xlsx/InvalidSpreadsheetError.js +55 -0
- package/commonjs/xlsx/InvalidSpreadsheetError.js.map +1 -0
- package/commonjs/xlsx/SheetNotFoundError.js +55 -0
- package/commonjs/xlsx/SheetNotFoundError.js.map +1 -0
- package/commonjs/xlsx/file/InputValidationStream.js +101 -0
- package/commonjs/xlsx/file/InputValidationStream.js.map +1 -0
- package/commonjs/xlsx/file/InputValidationStream.test.js.map +1 -0
- package/commonjs/xlsx/file/InvalidInputError.js +105 -0
- package/commonjs/xlsx/file/InvalidInputError.js.map +1 -0
- package/commonjs/xlsx/file/createFileTypeDetector.js +70 -0
- package/commonjs/xlsx/file/createFileTypeDetector.js.map +1 -0
- package/commonjs/xlsx/file/createFileTypeDetector.test.js.map +1 -0
- package/commonjs/xlsx/file/validateLeadingBytes.js +47 -0
- package/commonjs/xlsx/file/validateLeadingBytes.js.map +1 -0
- package/commonjs/xlsx/file/validateLeadingBytes.test.js.map +1 -0
- package/commonjs/xlsx/isDateFormat.js +32 -27
- package/commonjs/xlsx/isDateFormat.js.map +1 -1
- package/commonjs/xlsx/isDateFormatStyle.js +19 -21
- package/commonjs/xlsx/isDateFormatStyle.js.map +1 -1
- package/commonjs/xlsx/parseCell.js +252 -115
- package/commonjs/xlsx/parseCell.js.map +1 -1
- package/commonjs/xlsx/parseCellAddress.js +22 -18
- package/commonjs/xlsx/parseCellAddress.js.map +1 -1
- package/commonjs/xlsx/parseExcelDate.js +4 -124
- package/commonjs/xlsx/parseExcelDate.js.map +1 -1
- package/commonjs/xlsx/parseExcelDate.test.js.map +1 -1
- package/commonjs/xlsx/parseExcelTimestamp.js +139 -0
- package/commonjs/xlsx/parseExcelTimestamp.js.map +1 -0
- package/commonjs/xlsx/parseFilePaths.js +48 -47
- package/commonjs/xlsx/parseFilePaths.js.map +1 -1
- package/commonjs/xlsx/parseSharedStrings.js +91 -36
- package/commonjs/xlsx/parseSharedStrings.js.map +1 -1
- package/commonjs/xlsx/parseSheet.js +527 -69
- package/commonjs/xlsx/parseSheet.js.map +1 -1
- package/commonjs/xlsx/parseSpreadsheetContents.js +154 -83
- package/commonjs/xlsx/parseSpreadsheetContents.js.map +1 -1
- package/commonjs/xlsx/parseSpreadsheetInfo.js +60 -59
- package/commonjs/xlsx/parseSpreadsheetInfo.js.map +1 -1
- package/commonjs/xlsx/parseStyles.js +75 -75
- package/commonjs/xlsx/parseStyles.js.map +1 -1
- package/commonjs/xml/parseXml.js +112 -0
- package/commonjs/xml/parseXml.js.map +1 -0
- package/commonjs/xml/parseXml.test.js.map +1 -0
- package/commonjs/xml/parseXmlStream.js.map +1 -1
- package/commonjs/xml/parseXmlStream.sax.js +69 -28
- package/commonjs/xml/parseXmlStream.sax.js.map +1 -1
- package/commonjs/xml/parseXmlStream.saxen.js +66 -40
- package/commonjs/xml/parseXmlStream.saxen.js.map +1 -1
- package/commonjs/zip/UnzipError.js +55 -0
- package/commonjs/zip/UnzipError.js.map +1 -0
- package/commonjs/zip/unzipFromArrayBuffer.js +21 -1
- package/commonjs/zip/unzipFromArrayBuffer.js.map +1 -1
- package/commonjs/zip/unzipFromArrayBuffer.test.js.map +1 -0
- package/commonjs/zip/unzipFromStream.fflate.js +43 -35
- package/commonjs/zip/unzipFromStream.fflate.js.map +1 -1
- package/commonjs/zip/unzipFromStream.js +188 -6
- package/commonjs/zip/unzipFromStream.js.map +1 -1
- package/commonjs/zip/unzipFromStream.unzipper.js +19 -34
- package/commonjs/zip/unzipFromStream.unzipper.js.map +1 -1
- package/modules/export/convertInputToNodeStream.js +0 -12
- package/modules/export/convertInputToNodeStream.js.map +1 -1
- package/modules/export/parseSheet.js +13 -6
- package/modules/export/parseSheet.js.map +1 -1
- package/modules/export/readSheetBrowser.js +3 -5
- package/modules/export/readSheetBrowser.js.map +1 -1
- package/modules/export/readSheetNode.js +3 -5
- package/modules/export/readSheetNode.js.map +1 -1
- package/modules/export/readSheetUniversal.js +2 -2
- package/modules/export/readSheetUniversal.js.map +1 -1
- package/modules/export/readSheetWebWorker.js +7 -8
- package/modules/export/readSheetWebWorker.js.map +1 -1
- package/modules/export/readXlsxFileBrowser.js +3 -5
- package/modules/export/readXlsxFileBrowser.js.map +1 -1
- package/modules/export/readXlsxFileNode.js +3 -5
- package/modules/export/readXlsxFileNode.js.map +1 -1
- package/modules/export/readXlsxFileUniversal.js +2 -2
- package/modules/export/readXlsxFileUniversal.js.map +1 -1
- package/modules/export/readXlsxFileWebWorker.js +7 -8
- package/modules/export/readXlsxFileWebWorker.js.map +1 -1
- package/modules/export/unpackXlsxFileBrowser.js +15 -4
- package/modules/export/unpackXlsxFileBrowser.js.map +1 -1
- package/modules/export/unpackXlsxFileBrowser.test.js.map +1 -0
- package/modules/export/unpackXlsxFileNode.js +32 -5
- package/modules/export/unpackXlsxFileNode.js.map +1 -1
- package/modules/export/unpackXlsxFileNode.test.js.map +1 -0
- package/modules/export/unpackXlsxFileUniversal.js +14 -3
- package/modules/export/unpackXlsxFileUniversal.js.map +1 -1
- package/modules/export/unpackXlsxFileUniversal.test.js.map +1 -0
- package/modules/parseSheetData/parseSheetData.js +9 -6
- package/modules/parseSheetData/parseSheetData.js.map +1 -1
- package/modules/saxen/parser.js +1 -1
- package/modules/saxen/parser.js.map +1 -1
- package/modules/utility/convertValuesFromUint8ArraysToStrings.js +92 -0
- package/modules/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
- package/modules/xlsx/InvalidSpreadsheetError.js +50 -0
- package/modules/xlsx/InvalidSpreadsheetError.js.map +1 -0
- package/modules/xlsx/SheetNotFoundError.js +50 -0
- package/modules/xlsx/SheetNotFoundError.js.map +1 -0
- package/modules/xlsx/file/InputValidationStream.js +96 -0
- package/modules/xlsx/file/InputValidationStream.js.map +1 -0
- package/modules/xlsx/file/InputValidationStream.test.js.map +1 -0
- package/modules/xlsx/file/InvalidInputError.js +100 -0
- package/modules/xlsx/file/InvalidInputError.js.map +1 -0
- package/modules/xlsx/file/createFileTypeDetector.js +63 -0
- package/modules/xlsx/file/createFileTypeDetector.js.map +1 -0
- package/modules/xlsx/file/createFileTypeDetector.test.js.map +1 -0
- package/modules/xlsx/file/validateLeadingBytes.js +37 -0
- package/modules/xlsx/file/validateLeadingBytes.js.map +1 -0
- package/modules/xlsx/file/validateLeadingBytes.test.js.map +1 -0
- package/modules/xlsx/isDateFormat.js +31 -27
- package/modules/xlsx/isDateFormat.js.map +1 -1
- package/modules/xlsx/isDateFormatStyle.js +18 -21
- package/modules/xlsx/isDateFormatStyle.js.map +1 -1
- package/modules/xlsx/parseCell.js +251 -111
- package/modules/xlsx/parseCell.js.map +1 -1
- package/modules/xlsx/parseCellAddress.js +21 -18
- package/modules/xlsx/parseCellAddress.js.map +1 -1
- package/modules/xlsx/parseExcelDate.js +4 -124
- package/modules/xlsx/parseExcelDate.js.map +1 -1
- package/modules/xlsx/parseExcelDate.test.js.map +1 -1
- package/modules/xlsx/parseExcelTimestamp.js +133 -0
- package/modules/xlsx/parseExcelTimestamp.js.map +1 -0
- package/modules/xlsx/parseFilePaths.js +48 -47
- package/modules/xlsx/parseFilePaths.js.map +1 -1
- package/modules/xlsx/parseSharedStrings.js +91 -37
- package/modules/xlsx/parseSharedStrings.js.map +1 -1
- package/modules/xlsx/parseSheet.js +526 -68
- package/modules/xlsx/parseSheet.js.map +1 -1
- package/modules/xlsx/parseSpreadsheetContents.js +153 -81
- package/modules/xlsx/parseSpreadsheetContents.js.map +1 -1
- package/modules/xlsx/parseSpreadsheetInfo.js +60 -59
- package/modules/xlsx/parseSpreadsheetInfo.js.map +1 -1
- package/modules/xlsx/parseStyles.js +75 -75
- package/modules/xlsx/parseStyles.js.map +1 -1
- package/modules/xml/parseXml.js +106 -0
- package/modules/xml/parseXml.js.map +1 -0
- package/modules/xml/parseXml.test.js.map +1 -0
- package/modules/xml/parseXmlStream.js +2 -0
- package/modules/xml/parseXmlStream.js.map +1 -1
- package/modules/xml/parseXmlStream.sax.js +69 -28
- package/modules/xml/parseXmlStream.sax.js.map +1 -1
- package/modules/xml/parseXmlStream.saxen.js +67 -40
- package/modules/xml/parseXmlStream.saxen.js.map +1 -1
- package/modules/zip/UnzipError.js +49 -0
- package/modules/zip/UnzipError.js.map +1 -0
- package/modules/zip/unzipFromArrayBuffer.js +21 -1
- package/modules/zip/unzipFromArrayBuffer.js.map +1 -1
- package/modules/zip/unzipFromArrayBuffer.test.js.map +1 -0
- package/modules/zip/unzipFromStream.fflate.js +41 -35
- package/modules/zip/unzipFromStream.fflate.js.map +1 -1
- package/modules/zip/unzipFromStream.js +124 -1
- package/modules/zip/unzipFromStream.js.map +1 -1
- package/modules/zip/unzipFromStream.unzipper.js +19 -35
- package/modules/zip/unzipFromStream.unzipper.js.map +1 -1
- package/node/index.cjs +3 -0
- package/node/index.d.ts +16 -0
- package/node/index.js +3 -0
- package/package.json +5 -3
- package/types/InvalidInputError.d.ts +16 -0
- package/types/InvalidSpreadsheetError.d.ts +4 -0
- package/types/SheetNotFoundError.d.ts +4 -0
- package/universal/index.cjs +3 -0
- package/universal/index.d.ts +16 -0
- package/universal/index.js +3 -0
- package/web-worker/index.cjs +3 -0
- package/web-worker/index.d.ts +16 -0
- package/web-worker/index.js +3 -0
- package/commonjs/export/convertValuesFromUint8ArraysToStrings.js +0 -23
- package/commonjs/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
- package/commonjs/xlsx/convertCellsToData2dArray.js +0 -84
- package/commonjs/xlsx/convertCellsToData2dArray.js.map +0 -1
- package/commonjs/xlsx/dropEmptyColumns.js +0 -40
- package/commonjs/xlsx/dropEmptyColumns.js.map +0 -1
- package/commonjs/xlsx/dropEmptyColumns.test.js.map +0 -1
- package/commonjs/xlsx/dropEmptyRows.js +0 -43
- package/commonjs/xlsx/dropEmptyRows.js.map +0 -1
- package/commonjs/xlsx/dropEmptyRows.test.js.map +0 -1
- package/commonjs/xlsx/parseCellValue.js +0 -186
- package/commonjs/xlsx/parseCellValue.js.map +0 -1
- package/commonjs/xlsx/parseNumber.js +0 -20
- package/commonjs/xlsx/parseNumber.js.map +0 -1
- package/commonjs/xlsx/parseSharedString.js +0 -64
- package/commonjs/xlsx/parseSharedString.js.map +0 -1
- package/commonjs/xlsx/parseSheetData.js +0 -68
- package/commonjs/xlsx/parseSheetData.js.map +0 -1
- package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -29
- package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
- package/commonjs/xml/parseXmlStream.saxen.code.js +0 -953
- package/commonjs/xml/parseXmlStream.saxen.code.js.map +0 -1
- package/commonjs/xml/parseXmlStream.test.js.map +0 -1
- package/modules/export/convertValuesFromUint8ArraysToStrings.js +0 -17
- package/modules/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
- package/modules/xlsx/convertCellsToData2dArray.js +0 -77
- package/modules/xlsx/convertCellsToData2dArray.js.map +0 -1
- package/modules/xlsx/dropEmptyColumns.js +0 -34
- package/modules/xlsx/dropEmptyColumns.js.map +0 -1
- package/modules/xlsx/dropEmptyColumns.test.js.map +0 -1
- package/modules/xlsx/dropEmptyRows.js +0 -37
- package/modules/xlsx/dropEmptyRows.js.map +0 -1
- package/modules/xlsx/dropEmptyRows.test.js.map +0 -1
- package/modules/xlsx/parseCellValue.js +0 -180
- package/modules/xlsx/parseCellValue.js.map +0 -1
- package/modules/xlsx/parseNumber.js +0 -14
- package/modules/xlsx/parseNumber.js.map +0 -1
- package/modules/xlsx/parseSharedString.js +0 -55
- package/modules/xlsx/parseSharedString.js.map +0 -1
- package/modules/xlsx/parseSheetData.js +0 -55
- package/modules/xlsx/parseSheetData.js.map +0 -1
- package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -23
- package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
- package/modules/xml/parseXmlStream.saxen.code.js +0 -947
- package/modules/xml/parseXmlStream.saxen.code.js.map +0 -1
- package/modules/xml/parseXmlStream.test.js.map +0 -1
|
@@ -4,119 +4,259 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import parseExcelTimestamp from './parseExcelTimestamp.js';
|
|
8
|
+
import isDateFormatStyle from './isDateFormatStyle.js';
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
10
|
+
// An empty cell has `null` value.
|
|
11
|
+
var EMPTY_CELL_VALUE = null;
|
|
12
|
+
|
|
13
|
+
// This variable represents a cell with a `null` value.
|
|
14
|
+
// It is exported only to be specified as a dependency when using `worker-f`.
|
|
15
|
+
export var EMPTY_CELL = [null, EMPTY_CELL_VALUE];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parses a cell from the info extracted from XML.
|
|
19
|
+
* @param {string} [t] — `<c t/>` attribute value (cell type). One of: b (Boolean), e (Error), n (Number), d (Date), s (String).
|
|
20
|
+
* @param {string} [s] — `<c s/>` attribute value (formatting style ID). When present, should be a stringified zero-based index of the formatting style for a numberic cell.
|
|
21
|
+
* @param {string} [v] — `<v/>` element text content (value). Will be `undefined` if the `<v/>` element absent. Will be an empty string `""` if the `<v/>` element is present but is empty.
|
|
22
|
+
* @param {string} [inlineString] — Inline string value.
|
|
23
|
+
* @param {any[]} parameters
|
|
24
|
+
* @returns {[string|null,string|number|boolean|null] | string} Either `[type, value]` or `error`, where `value` is the cell value, `type` depends on the type of `value` and could be one of: 's' (string), 'b' (boolean), 'n' (number string), 'd' (date timestamp), 'e' (formula cell error), `null` (null); `error` is an error message: `VALUE_MISSING`, `VALUE_INVALID`, `FORMAT_INVALID`, `TYPE_INVALID`.
|
|
25
|
+
*/
|
|
26
|
+
export default function parseCell(t, s, v, inlineString, _ref) {
|
|
27
|
+
var _ref2 = _slicedToArray(_ref, 6),
|
|
28
|
+
sharedStrings = _ref2[0],
|
|
29
|
+
styles = _ref2[1],
|
|
30
|
+
epoch1904 = _ref2[2],
|
|
31
|
+
defaultDateFormat = _ref2[3],
|
|
32
|
+
dateTemplateParser = _ref2[4],
|
|
33
|
+
parseNumberCustom = _ref2[5];
|
|
34
|
+
// Available Excel cell types:
|
|
35
|
+
// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md
|
|
36
|
+
//
|
|
37
|
+
// Some other document (seems to be old):
|
|
38
|
+
// http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html
|
|
39
|
+
//
|
|
40
|
+
// The default cell type is "n" (numeric), according to XLSX specification.
|
|
41
|
+
//
|
|
42
|
+
switch (t || 'n') {
|
|
43
|
+
// `t="str"` means that the cell value is calculated using a formula.
|
|
44
|
+
// The formula is defined as the text of a child `<f/>` element.
|
|
45
|
+
//
|
|
46
|
+
// It could optionally include a `<v/>` element whose text is the cached result
|
|
47
|
+
// of the calculation from the last time the file was saved in a spreadsheet editor application.
|
|
48
|
+
//
|
|
49
|
+
// An optional `<v/>` element holds a pre-computed result of the formula defined by `<f/>`.
|
|
50
|
+
//
|
|
51
|
+
// Example:
|
|
52
|
+
//
|
|
53
|
+
// <c r="B3" t="str">
|
|
54
|
+
// <f>CONCATENATE(C1,D1)</f>
|
|
55
|
+
// <v>C1ValueD1Value</v>
|
|
56
|
+
// </c>
|
|
57
|
+
//
|
|
58
|
+
// Here's a guide on formulas in XLSX files:
|
|
59
|
+
// https://github.com/MiniMax-AI/skills/blob/main/skills/minimax-xlsx/references/validate.md
|
|
60
|
+
//
|
|
61
|
+
case 'str':
|
|
62
|
+
// The `<v/>` element could be absent because it's not required to be pre-computed by the spec.
|
|
63
|
+
// In such case, `v` argument value would be `undefined`.
|
|
64
|
+
// Because this package can't include the whole formula calculation engine,
|
|
65
|
+
// it has to interpret this situation as an error.
|
|
66
|
+
if (v === undefined) {
|
|
67
|
+
return 'VALUE_MISSING';
|
|
68
|
+
}
|
|
69
|
+
// The `<v/>` element could be present but its text content could be empty
|
|
70
|
+
// because the formula returns an empty string.
|
|
71
|
+
// For example, a valid case of `v` argument value being an empty string `""` is when
|
|
72
|
+
// a formula in cell `A1` is `=CONCATENATE(B1,C1)` and both `B1` and `C1` cells are empty.
|
|
73
|
+
if (!v) {
|
|
74
|
+
return EMPTY_CELL;
|
|
75
|
+
}
|
|
76
|
+
return ['s', v];
|
|
77
|
+
|
|
78
|
+
// `t="inlineStr"` means that `<is/>` holds the string value.
|
|
79
|
+
//
|
|
80
|
+
// Inside a `<c t="inlineStr"/>`, the specification requires there to exist an `<is/>` element,
|
|
81
|
+
// and within that `<is/>` element it requires to exist a `<t/>` element.
|
|
82
|
+
//
|
|
83
|
+
// Example:
|
|
84
|
+
//
|
|
85
|
+
// <c r="A1" s="1" t="inlineStr">
|
|
86
|
+
// <is>
|
|
87
|
+
// <t>
|
|
88
|
+
// Test 123
|
|
89
|
+
// </t>
|
|
90
|
+
// </is>
|
|
91
|
+
// </c>
|
|
92
|
+
//
|
|
93
|
+
case 'inlineStr':
|
|
94
|
+
if (inlineString === undefined) {
|
|
95
|
+
return 'VALUE_MISSING';
|
|
96
|
+
}
|
|
97
|
+
return ['s', inlineString];
|
|
98
|
+
|
|
99
|
+
// `type="s"` means that the string value is stored in the Shared Strings Table.
|
|
100
|
+
// This way it attempts to compress the `.xlsx` file by reusing all string values
|
|
101
|
+
// in case they repeat throughout the spreadsheet.
|
|
102
|
+
//
|
|
103
|
+
// This optimization can't be used when writing an `.xlsx` file in a "streaming"
|
|
104
|
+
// fashion, i.e. when the entire spreadsheet data is not known in adavance
|
|
105
|
+
// at the start of writing the file.
|
|
106
|
+
// But it can be used in all other situations. And hence, it is used.
|
|
107
|
+
// So this is the most common cell type, actually.
|
|
108
|
+
//
|
|
109
|
+
// Example:
|
|
110
|
+
//
|
|
111
|
+
// <c r="A3" t="s">
|
|
112
|
+
// <v>3</v>
|
|
113
|
+
// </c>
|
|
114
|
+
//
|
|
115
|
+
case 's':
|
|
116
|
+
// If a cell has no value then there's no `<c/>` element for it.
|
|
117
|
+
// If a `<c/>` element exists then it's not empty.
|
|
118
|
+
// The `<v/>` element's text is a zero-based index in the "shared strings" dictionary.
|
|
119
|
+
if (!v) {
|
|
120
|
+
return 'VALUE_MISSING';
|
|
121
|
+
}
|
|
122
|
+
var sharedStringIndex = Number(v);
|
|
123
|
+
// The shared string index value could be:
|
|
124
|
+
// * not a number
|
|
125
|
+
// * a number but a fractional one
|
|
126
|
+
// * an integer that is out of bounds of the shared strings array
|
|
127
|
+
if (isNaN(sharedStringIndex) || sharedStrings[sharedStringIndex] === undefined) {
|
|
128
|
+
return 'VALUE_INVALID';
|
|
129
|
+
}
|
|
130
|
+
return ['s', sharedStrings[sharedStringIndex]];
|
|
131
|
+
|
|
132
|
+
// Boolean (TRUE/FALSE) values are stored as either "1" or "0" in cells of type "b".
|
|
133
|
+
//
|
|
134
|
+
// Example:
|
|
135
|
+
//
|
|
136
|
+
// <c r="A1" t="b">
|
|
137
|
+
// <v>1</v>
|
|
138
|
+
// </c>
|
|
139
|
+
//
|
|
140
|
+
case 'b':
|
|
141
|
+
if (!v) {
|
|
142
|
+
return 'VALUE_MISSING';
|
|
143
|
+
}
|
|
144
|
+
if (v === '1') {
|
|
145
|
+
return ['b', true];
|
|
146
|
+
}
|
|
147
|
+
if (v === '0') {
|
|
148
|
+
return ['b', false];
|
|
149
|
+
}
|
|
150
|
+
return 'VALUE_INVALID';
|
|
151
|
+
|
|
152
|
+
// If cell type is "e", the `<v/>` element's text is an error code string (required).
|
|
153
|
+
//
|
|
154
|
+
// Example:
|
|
155
|
+
//
|
|
156
|
+
// <c r="A1" t="e">
|
|
157
|
+
// <f>1/0</f>
|
|
158
|
+
// <v>#DIV/0!</v>
|
|
159
|
+
// </c>
|
|
160
|
+
//
|
|
161
|
+
case 'e':
|
|
162
|
+
// Examples of error codes:
|
|
163
|
+
//
|
|
164
|
+
// '#NULL!'
|
|
165
|
+
// '#DIV/0!'
|
|
166
|
+
// '#VALUE!'
|
|
167
|
+
// '#REF!'
|
|
168
|
+
// '#NAME!'
|
|
169
|
+
// '#NUM!'
|
|
170
|
+
// '#N/A'
|
|
171
|
+
// '#SPILL!'
|
|
172
|
+
//
|
|
173
|
+
// The description of each error could be read in the formulas guide:
|
|
174
|
+
// https://github.com/MiniMax-AI/skills/blob/main/skills/minimax-xlsx/references/validate.md
|
|
175
|
+
//
|
|
176
|
+
if (!v) {
|
|
177
|
+
return 'VALUE_MISSING';
|
|
178
|
+
}
|
|
179
|
+
return ['e', v];
|
|
180
|
+
|
|
181
|
+
// XLSX supports date cells of type "d", though it seems like it (almost?) never
|
|
182
|
+
// uses type "d" for storing dates, preferring type "n" and numeric timestamp instead.
|
|
183
|
+
// The value of a "d" cell is supposedly a string in "ISO 8601" format.
|
|
184
|
+
// I haven't seen an `.xlsx` file having such cells.
|
|
185
|
+
//
|
|
186
|
+
// Example:
|
|
187
|
+
//
|
|
188
|
+
// <c r="A1" s="1" t="d">
|
|
189
|
+
// <v>
|
|
190
|
+
// 2021-06-10T00:47:45.700Z
|
|
191
|
+
// </v>
|
|
192
|
+
// </c>
|
|
193
|
+
//
|
|
194
|
+
case 'd':
|
|
195
|
+
if (!v) {
|
|
196
|
+
return EMPTY_CELL;
|
|
197
|
+
}
|
|
198
|
+
var parsedDate = new Date(v);
|
|
199
|
+
if (isNaN(parsedDate.valueOf())) {
|
|
200
|
+
return 'VALUE_INVALID';
|
|
201
|
+
}
|
|
202
|
+
return ['d', parsedDate.getTime()];
|
|
203
|
+
|
|
204
|
+
// type "n" is used for numeric cells.
|
|
205
|
+
//
|
|
206
|
+
// An optional `s` attribute defines how this number should be formatted —
|
|
207
|
+
// it should be a zero-based index of the style (XF record) in `styles.xml`.
|
|
208
|
+
//
|
|
209
|
+
// Example:
|
|
210
|
+
//
|
|
211
|
+
// <c r="A1" s="1" t="n">
|
|
212
|
+
// <v>123.45</v>
|
|
213
|
+
// </c>
|
|
214
|
+
//
|
|
215
|
+
case 'n':
|
|
216
|
+
// Numeric cell value is allowed to be missing in the XLSX specification
|
|
217
|
+
// because "n" is the default type of a cell, so it ends up representing empty cells too.
|
|
218
|
+
if (!v) {
|
|
219
|
+
return EMPTY_CELL;
|
|
220
|
+
}
|
|
221
|
+
// XLSX does support `type: "d"` cells for storing dates, but it's not commonly used.
|
|
222
|
+
// Instead, it prefers using `type: "n"` cells for storing dates as timestamps
|
|
223
|
+
// with a corresponding `s` formatting style.
|
|
224
|
+
if (s) {
|
|
225
|
+
var styleId = Number(s);
|
|
226
|
+
// The style ID value could be:
|
|
227
|
+
// * not a number
|
|
228
|
+
// * a number but a fractional one
|
|
229
|
+
// * an integer that is out of bounds of the styles array
|
|
230
|
+
if (isNaN(styleId) || styles[styleId] === undefined) {
|
|
231
|
+
return 'FORMAT_INVALID';
|
|
232
|
+
}
|
|
233
|
+
// Whether it's a date cell or just a numeric cell could only be determined
|
|
234
|
+
// by looking at the formatting style.
|
|
235
|
+
if (isDateFormatStyle(styles[styleId], defaultDateFormat, dateTemplateParser)) {
|
|
236
|
+
var timestamp = Number(v);
|
|
237
|
+
if (isNaN(timestamp)) {
|
|
238
|
+
return 'VALUE_INVALID';
|
|
239
|
+
}
|
|
240
|
+
// First, parse the "serial date" number from string.
|
|
241
|
+
// Then convert the "serial date" number to a date timestamp.
|
|
242
|
+
return ['d', parseExcelTimestamp(timestamp, epoch1904)];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// Return the cell value as a number,
|
|
246
|
+
// unless custom `parseNumber()` function was passed,
|
|
247
|
+
// in which case return the number as an unparsed string.
|
|
248
|
+
// Some people prefer passing a custom `parseNumber()` function
|
|
249
|
+
// to parse "big integers" without losing any precision.
|
|
250
|
+
if (parseNumberCustom) {
|
|
251
|
+
return ['n', v];
|
|
252
|
+
}
|
|
253
|
+
var number = Number(v);
|
|
254
|
+
if (isNaN(number)) {
|
|
255
|
+
return 'VALUE_INVALID';
|
|
118
256
|
}
|
|
119
|
-
|
|
257
|
+
return ['n', number];
|
|
258
|
+
default:
|
|
259
|
+
return 'TYPE_INVALID';
|
|
120
260
|
}
|
|
121
261
|
}
|
|
122
262
|
//# sourceMappingURL=parseCell.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCell.js","names":["parseCellValue","parseCellAddress","parseCell","attributes","value","inlineString","sharedStrings","styles","epoch1904","options","_parseCellAddress","r","_parseCellAddress2","_slicedToArray","row","column","type","t","styleId","s","Number","undefined","createInitialStateInCell","v","is","rPh","onOpenTagInCell","tagName","state","onCloseTagInCell","onTextInCell","text"],"sources":["../../source/xlsx/parseCell.js"],"sourcesContent":["import parseCellValue from './parseCellValue.js'\r\nimport parseCellAddress from './parseCellAddress.js'\r\n\r\n// Example of a `<c/>`ell element:\r\n//\r\n// <c>\r\n// <f>string</f> — formula.\r\n// <v>string</v> — formula pre-computed value.\r\n// <is>\r\n// <t>string</t> — an `inlineStr` string (rather than a \"common string\" from a dictionary).\r\n// <r>\r\n// <rPr>\r\n// ...\r\n// </rPr>\r\n// <t>string</t>\r\n// </r>\r\n// <rPh sb=\"1\" eb=\"1\">\r\n// <t>string</t>\r\n// </rPh>\r\n// <phoneticPr fontId=\"1\"/>\r\n// </is>\r\n// <extLst>\r\n// <ext>\r\n// <!--any element-->\r\n// </ext>\r\n// </extLst>\r\n// </c>\r\n//\r\nexport default function parseCell(\r\n attributes,\r\n value,\r\n inlineString,\r\n sharedStrings,\r\n styles,\r\n epoch1904,\r\n options\r\n) {\r\n const [row, column] = parseCellAddress(attributes.r)\r\n const type = attributes.t\r\n const styleId = attributes.s ? Number(attributes.s) : undefined\r\n\r\n return {\r\n row,\r\n column,\r\n value: parseCellValue(value, type, {\r\n inlineString,\r\n styleId,\r\n styles,\r\n sharedStrings,\r\n epoch1904,\r\n options\r\n })\r\n }\r\n}\r\n\r\nexport function createInitialStateInCell() {\r\n return {\r\n v: false,\r\n is: false,\r\n t: false,\r\n r: false,\r\n rPh: false,\r\n value: undefined,\r\n inlineString: undefined,\r\n attributes: undefined\r\n }\r\n}\r\n\r\nexport function onOpenTagInCell(tagName, attributes, state) {\r\n if (tagName === 'v') {\r\n state.v = true\r\n } else if (tagName === 'is') {\r\n // The possible children of <is> are:\r\n // * <t> (Text): The standard child to hold plain, simple text.\r\n // * <r> (Rich Text Run): Used for applying different formatting styles (like bold or italic) to specific segments of text within a single cell.\r\n // * <rPh> (Phonetic Run): Used primarily for East Asian languages to provide phonetic reading/pronunciation data (e.g., furigana in Japanese). It associates a phonetic pronunciation run right alongside the base string text tag <t>.\r\n // * <phoneticPr> (Phonetic Properties): Defines formatting and settings for the phonetic text.\r\n state.is = true\r\n state.inlineString = ''\r\n } else if (tagName === 't') {\r\n state.t = true\r\n } else if (tagName === 'r') {\r\n // The possible children of <r/> are:\r\n // * <rPr> (Run Properties): The formatting properties for the text (font, size, color, bold, italic, etc.).\r\n // * <t> (Text): The actual text payload.\r\n // * <rPh> (Phonetic Run): Phonetic pronunciation guidance (used for East Asian languages like Japanese). It associates a phonetic pronunciation run right alongside the base string text tag <t>.\r\n state.r = true\r\n } else if (tagName === 'rPh') {\r\n // The possible children of <rPh/> are:\r\n // * <t> (Text): Contains the actual phonetic text or reading (usually in Katakana for Japanese) that corresponds to the associated character string.\r\n state.rPh = true\r\n }\r\n}\r\n\r\nexport function onCloseTagInCell(tagName, state) {\r\n if (tagName === 'v') {\r\n state.v = false\r\n } else if (tagName === 'is') {\r\n state.is = false\r\n } else if (tagName === 't') {\r\n state.t = false\r\n } else if (tagName === 'r') {\r\n state.r = false\r\n } else if (tagName === 'rPh') {\r\n state.rPh = false\r\n }\r\n}\r\n\r\nexport function onTextInCell(text, state) {\r\n if (state.v) {\r\n state.value = text\r\n } else if (state.is) {\r\n if (state.rPh) {\r\n // Ignore anything inside `<rPh/>` tags\r\n } else if (state.t) {\r\n if (state.r) {\r\n // An `<r/>` element could contain multiple `<t/>` elements,\r\n // the text content from all of which should be concatenated.\r\n state.inlineString += text\r\n } else {\r\n state.inlineString = text\r\n }\r\n }\r\n }\r\n}\r\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"parseCell.js","names":["parseExcelTimestamp","isDateFormatStyle","EMPTY_CELL_VALUE","EMPTY_CELL","parseCell","t","s","v","inlineString","_ref","_ref2","_slicedToArray","sharedStrings","styles","epoch1904","defaultDateFormat","dateTemplateParser","parseNumberCustom","undefined","sharedStringIndex","Number","isNaN","parsedDate","Date","valueOf","getTime","styleId","timestamp","number"],"sources":["../../source/xlsx/parseCell.js"],"sourcesContent":["import parseExcelTimestamp from './parseExcelTimestamp.js'\r\nimport isDateFormatStyle from './isDateFormatStyle.js'\r\n\r\n// An empty cell has `null` value.\r\nconst EMPTY_CELL_VALUE = null\r\n\r\n// This variable represents a cell with a `null` value.\r\n// It is exported only to be specified as a dependency when using `worker-f`.\r\nexport const EMPTY_CELL = [null, EMPTY_CELL_VALUE]\r\n\r\n/**\r\n * Parses a cell from the info extracted from XML.\r\n * @param {string} [t] — `<c t/>` attribute value (cell type). One of: b (Boolean), e (Error), n (Number), d (Date), s (String).\r\n * @param {string} [s] — `<c s/>` attribute value (formatting style ID). When present, should be a stringified zero-based index of the formatting style for a numberic cell.\r\n * @param {string} [v] — `<v/>` element text content (value). Will be `undefined` if the `<v/>` element absent. Will be an empty string `\"\"` if the `<v/>` element is present but is empty.\r\n * @param {string} [inlineString] — Inline string value.\r\n * @param {any[]} parameters\r\n * @returns {[string|null,string|number|boolean|null] | string} Either `[type, value]` or `error`, where `value` is the cell value, `type` depends on the type of `value` and could be one of: 's' (string), 'b' (boolean), 'n' (number string), 'd' (date timestamp), 'e' (formula cell error), `null` (null); `error` is an error message: `VALUE_MISSING`, `VALUE_INVALID`, `FORMAT_INVALID`, `TYPE_INVALID`.\r\n */\r\nexport default function parseCell(\r\n t,\r\n s,\r\n v,\r\n inlineString,\r\n [\r\n sharedStrings,\r\n styles,\r\n epoch1904,\r\n defaultDateFormat,\r\n dateTemplateParser,\r\n parseNumberCustom\r\n ]\r\n) {\r\n // Available Excel cell types:\r\n // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\n //\r\n // Some other document (seems to be old):\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html\r\n //\r\n // The default cell type is \"n\" (numeric), according to XLSX specification.\r\n //\r\n switch (t || 'n') {\r\n // `t=\"str\"` means that the cell value is calculated using a formula.\r\n // The formula is defined as the text of a child `<f/>` element.\r\n //\r\n // It could optionally include a `<v/>` element whose text is the cached result\r\n // of the calculation from the last time the file was saved in a spreadsheet editor application.\r\n //\r\n // An optional `<v/>` element holds a pre-computed result of the formula defined by `<f/>`.\r\n //\r\n // Example:\r\n //\r\n // <c r=\"B3\" t=\"str\">\r\n // \t<f>CONCATENATE(C1,D1)</f>\r\n // \t<v>C1ValueD1Value</v>\r\n // </c>\r\n //\r\n // Here's a guide on formulas in XLSX files:\r\n // https://github.com/MiniMax-AI/skills/blob/main/skills/minimax-xlsx/references/validate.md\r\n //\r\n case 'str':\r\n // The `<v/>` element could be absent because it's not required to be pre-computed by the spec.\r\n // In such case, `v` argument value would be `undefined`.\r\n // Because this package can't include the whole formula calculation engine,\r\n // it has to interpret this situation as an error.\r\n if (v === undefined) {\r\n return 'VALUE_MISSING'\r\n }\r\n // The `<v/>` element could be present but its text content could be empty\r\n // because the formula returns an empty string.\r\n // For example, a valid case of `v` argument value being an empty string `\"\"` is when\r\n // a formula in cell `A1` is `=CONCATENATE(B1,C1)` and both `B1` and `C1` cells are empty.\r\n if (!v) {\r\n return EMPTY_CELL\r\n }\r\n return ['s', v]\r\n\r\n // `t=\"inlineStr\"` means that `<is/>` holds the string value.\r\n //\r\n // Inside a `<c t=\"inlineStr\"/>`, the specification requires there to exist an `<is/>` element,\r\n // and within that `<is/>` element it requires to exist a `<t/>` element.\r\n //\r\n // Example:\r\n //\r\n // <c r=\"A1\" s=\"1\" t=\"inlineStr\">\r\n // <is>\r\n // <t>\r\n // Test 123\r\n // </t>\r\n // </is>\r\n // </c>\r\n //\r\n case 'inlineStr':\r\n if (inlineString === undefined) {\r\n return 'VALUE_MISSING'\r\n }\r\n return ['s', inlineString]\r\n\r\n // `type=\"s\"` means that the string value is stored in the Shared Strings Table.\r\n // This way it attempts to compress the `.xlsx` file by reusing all string values\r\n // in case they repeat throughout the spreadsheet.\r\n //\r\n // This optimization can't be used when writing an `.xlsx` file in a \"streaming\"\r\n // fashion, i.e. when the entire spreadsheet data is not known in adavance\r\n // at the start of writing the file.\r\n // But it can be used in all other situations. And hence, it is used.\r\n // So this is the most common cell type, actually.\r\n //\r\n // Example:\r\n //\r\n // <c r=\"A3\" t=\"s\">\r\n // <v>3</v>\r\n // </c>\r\n //\r\n case 's':\r\n // If a cell has no value then there's no `<c/>` element for it.\r\n // If a `<c/>` element exists then it's not empty.\r\n // The `<v/>` element's text is a zero-based index in the \"shared strings\" dictionary.\r\n if (!v) {\r\n return 'VALUE_MISSING'\r\n }\r\n const sharedStringIndex = Number(v)\r\n // The shared string index value could be:\r\n // * not a number\r\n // * a number but a fractional one\r\n // * an integer that is out of bounds of the shared strings array\r\n if (isNaN(sharedStringIndex) || sharedStrings[sharedStringIndex] === undefined) {\r\n return 'VALUE_INVALID'\r\n }\r\n return ['s', sharedStrings[sharedStringIndex]]\r\n\r\n // Boolean (TRUE/FALSE) values are stored as either \"1\" or \"0\" in cells of type \"b\".\r\n //\r\n // Example:\r\n //\r\n // <c r=\"A1\" t=\"b\">\r\n // <v>1</v>\r\n // </c>\r\n //\r\n case 'b':\r\n if (!v) {\r\n return 'VALUE_MISSING'\r\n }\r\n if (v === '1') {\r\n return ['b', true]\r\n }\r\n if (v === '0') {\r\n return ['b', false]\r\n }\r\n return 'VALUE_INVALID'\r\n\r\n // If cell type is \"e\", the `<v/>` element's text is an error code string (required).\r\n //\r\n // Example:\r\n //\r\n // <c r=\"A1\" t=\"e\">\r\n // <f>1/0</f>\r\n // <v>#DIV/0!</v>\r\n // </c>\r\n //\r\n case 'e':\r\n // Examples of error codes:\r\n //\r\n // '#NULL!'\r\n // '#DIV/0!'\r\n // '#VALUE!'\r\n // '#REF!'\r\n // '#NAME!'\r\n // '#NUM!'\r\n // '#N/A'\r\n // '#SPILL!'\r\n //\r\n // The description of each error could be read in the formulas guide:\r\n // https://github.com/MiniMax-AI/skills/blob/main/skills/minimax-xlsx/references/validate.md\r\n //\r\n if (!v) {\r\n return 'VALUE_MISSING'\r\n }\r\n return ['e', v]\r\n\r\n // XLSX supports date cells of type \"d\", though it seems like it (almost?) never\r\n // uses type \"d\" for storing dates, preferring type \"n\" and numeric timestamp instead.\r\n // The value of a \"d\" cell is supposedly a string in \"ISO 8601\" format.\r\n // I haven't seen an `.xlsx` file having such cells.\r\n //\r\n // Example:\r\n //\r\n // <c r=\"A1\" s=\"1\" t=\"d\">\r\n // <v>\r\n // 2021-06-10T00:47:45.700Z\r\n // </v>\r\n // </c>\r\n //\r\n case 'd':\r\n if (!v) {\r\n return EMPTY_CELL\r\n }\r\n const parsedDate = new Date(v)\r\n if (isNaN(parsedDate.valueOf())) {\r\n return 'VALUE_INVALID'\r\n }\r\n return ['d', parsedDate.getTime()]\r\n\r\n // type \"n\" is used for numeric cells.\r\n //\r\n // An optional `s` attribute defines how this number should be formatted — \r\n // it should be a zero-based index of the style (XF record) in `styles.xml`.\r\n //\r\n // Example:\r\n //\r\n // <c r=\"A1\" s=\"1\" t=\"n\">\r\n // <v>123.45</v>\r\n // </c>\r\n //\r\n case 'n':\r\n // Numeric cell value is allowed to be missing in the XLSX specification\r\n // because \"n\" is the default type of a cell, so it ends up representing empty cells too.\r\n if (!v) {\r\n return EMPTY_CELL\r\n }\r\n // XLSX does support `type: \"d\"` cells for storing dates, but it's not commonly used.\r\n // Instead, it prefers using `type: \"n\"` cells for storing dates as timestamps\r\n // with a corresponding `s` formatting style.\r\n if (s) {\r\n const styleId = Number(s)\r\n // The style ID value could be:\r\n // * not a number\r\n // * a number but a fractional one\r\n // * an integer that is out of bounds of the styles array\r\n if (isNaN(styleId) || styles[styleId] === undefined) {\r\n return 'FORMAT_INVALID'\r\n }\r\n // Whether it's a date cell or just a numeric cell could only be determined\r\n // by looking at the formatting style.\r\n if (isDateFormatStyle(styles[styleId], defaultDateFormat, dateTemplateParser)) {\r\n const timestamp = Number(v)\r\n if (isNaN(timestamp)) {\r\n return 'VALUE_INVALID'\r\n }\r\n // First, parse the \"serial date\" number from string.\r\n // Then convert the \"serial date\" number to a date timestamp.\r\n return ['d', parseExcelTimestamp(timestamp, epoch1904)]\r\n }\r\n }\r\n // Return the cell value as a number,\r\n // unless custom `parseNumber()` function was passed,\r\n // in which case return the number as an unparsed string.\r\n // Some people prefer passing a custom `parseNumber()` function\r\n // to parse \"big integers\" without losing any precision.\r\n if (parseNumberCustom) {\r\n return ['n', v]\r\n }\r\n const number = Number(v)\r\n if (isNaN(number)) {\r\n return 'VALUE_INVALID'\r\n }\r\n return ['n', number]\r\n\r\n default:\r\n return 'TYPE_INVALID'\r\n }\r\n}"],"mappings":"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"}
|
|
@@ -13,24 +13,15 @@ export default function parseCellAddress(coordinatesString) {
|
|
|
13
13
|
// Coordinate examples: "AA2091", "R988", "B1".
|
|
14
14
|
var _coordinatesString$sp = coordinatesString.split(/(\d+)/),
|
|
15
15
|
_coordinatesString$sp2 = _slicedToArray(_coordinatesString$sp, 2),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return [
|
|
19
|
-
// Row number (starting at `1`).
|
|
20
|
-
Number(row),
|
|
21
|
-
// Column number (starting at `1`).
|
|
22
|
-
// It's not clear if the `column` part could ever be non-trimmed,
|
|
23
|
-
// but this `.trim()` call was already here when I copied this code from somewhere.
|
|
24
|
-
getColumnNumberFromColumnLetters(column.trim())];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Maps "A1"-like coordinates to `{ row, column }` numeric coordinates.
|
|
28
|
-
var LETTERS = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
|
16
|
+
columnLetters = _coordinatesString$sp2[0],
|
|
17
|
+
rowNumberString = _coordinatesString$sp2[1];
|
|
29
18
|
|
|
30
|
-
// Converts a letter coordinate to a digit coordinate.
|
|
31
|
-
// Examples: "A" -> 1, "B" -> 2, "Z" -> 26, "AA" -> 27, etc.
|
|
32
|
-
|
|
33
|
-
//
|
|
19
|
+
// Converts a letter coordinate to a digit coordinate.
|
|
20
|
+
// Examples: "A" -> 1, "B" -> 2, "Z" -> 26, "AA" -> 27, etc.
|
|
21
|
+
//
|
|
22
|
+
// This function is inlined only to avoid passing it in `worker-f` dependencies.
|
|
23
|
+
// Otherwise, it would throw: "getColumnNumberFromColumnLetters is not defined".
|
|
24
|
+
//
|
|
34
25
|
var n = 0;
|
|
35
26
|
var i = 0;
|
|
36
27
|
while (i < columnLetters.length) {
|
|
@@ -38,6 +29,18 @@ function getColumnNumberFromColumnLetters(columnLetters) {
|
|
|
38
29
|
n += LETTERS.indexOf(columnLetters[i]);
|
|
39
30
|
i++;
|
|
40
31
|
}
|
|
41
|
-
|
|
32
|
+
var columnNumberFromColumnLetters = n;
|
|
33
|
+
return [
|
|
34
|
+
// Row number (starting at `1`).
|
|
35
|
+
Number(rowNumberString),
|
|
36
|
+
// Column number (starting at `1`).
|
|
37
|
+
columnNumberFromColumnLetters];
|
|
42
38
|
}
|
|
39
|
+
|
|
40
|
+
// Maps "A1"-like coordinates to `{ row, column }` numeric coordinates.
|
|
41
|
+
//
|
|
42
|
+
// This is `export`ed only to be passed in `worker-f` dependencies.
|
|
43
|
+
// Otherwise, it would throw: "LETTERS is not defined".
|
|
44
|
+
//
|
|
45
|
+
export var LETTERS = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
|
43
46
|
//# sourceMappingURL=parseCellAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCellAddress.js","names":["parseCellAddress","coordinatesString","_coordinatesString$sp","split","_coordinatesString$sp2","_slicedToArray","
|
|
1
|
+
{"version":3,"file":"parseCellAddress.js","names":["parseCellAddress","coordinatesString","_coordinatesString$sp","split","_coordinatesString$sp2","_slicedToArray","columnLetters","rowNumberString","n","i","length","LETTERS","indexOf","columnNumberFromColumnLetters","Number"],"sources":["../../source/xlsx/parseCellAddress.js"],"sourcesContent":["/**\r\n * Parses XLSX cell address into a row number and a column number.\r\n * @param {string} coordinatesString\r\n * @returns {number[]} Returns `[rowNumber, columnNumber]`\r\n */\r\nexport default function parseCellAddress(coordinatesString) {\r\n // Coordinate examples: \"AA2091\", \"R988\", \"B1\".\r\n const [columnLetters, rowNumberString] = coordinatesString.split(/(\\d+)/)\r\n\r\n // Converts a letter coordinate to a digit coordinate.\r\n // Examples: \"A\" -> 1, \"B\" -> 2, \"Z\" -> 26, \"AA\" -> 27, etc.\r\n //\r\n // This function is inlined only to avoid passing it in `worker-f` dependencies.\r\n // Otherwise, it would throw: \"getColumnNumberFromColumnLetters is not defined\".\r\n //\r\n let n = 0\r\n let i = 0\r\n while (i < columnLetters.length) {\r\n n *= 26\r\n n += LETTERS.indexOf(columnLetters[i])\r\n i++\r\n }\r\n const columnNumberFromColumnLetters = n\r\n\r\n return [\r\n // Row number (starting at `1`).\r\n Number(rowNumberString),\r\n // Column number (starting at `1`).\r\n columnNumberFromColumnLetters\r\n ]\r\n}\r\n\r\n// Maps \"A1\"-like coordinates to `{ row, column }` numeric coordinates.\r\n//\r\n// This is `export`ed only to be passed in `worker-f` dependencies.\r\n// Otherwise, it would throw: \"LETTERS is not defined\".\r\n//\r\nexport const LETTERS = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\r\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,gBAAgBA,CAACC,iBAAiB,EAAE;EAC1D;EACA,IAAAC,qBAAA,GAAyCD,iBAAiB,CAACE,KAAK,CAAC,OAAO,CAAC;IAAAC,sBAAA,GAAAC,cAAA,CAAAH,qBAAA;IAAlEI,aAAa,GAAAF,sBAAA;IAAEG,eAAe,GAAAH,sBAAA;;EAErC;EACA;EACA;EACA;EACA;EACA;EACA,IAAII,CAAC,GAAG,CAAC;EACT,IAAIC,CAAC,GAAG,CAAC;EACT,OAAOA,CAAC,GAAGH,aAAa,CAACI,MAAM,EAAE;IAC/BF,CAAC,IAAI,EAAE;IACPA,CAAC,IAAIG,OAAO,CAACC,OAAO,CAACN,aAAa,CAACG,CAAC,CAAC,CAAC;IACtCA,CAAC,EAAE;EACL;EACA,IAAMI,6BAA6B,GAAGL,CAAC;EAEvC,OAAO;EACL;EACAM,MAAM,CAACP,eAAe,CAAC;EACvB;EACAM,6BAA6B,CAC9B;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMF,OAAO,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC"}
|