read-excel-file 5.7.1 → 5.8.0
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 +10 -0
- package/README.md +45 -19
- package/bundle/read-excel-file.min.js +1 -1
- package/bundle/read-excel-file.min.js.map +1 -1
- package/commonjs/read/coordinates.js +7 -10
- package/commonjs/read/coordinates.js.map +1 -1
- package/commonjs/read/dropEmptyColumns.js +6 -18
- package/commonjs/read/dropEmptyColumns.js.map +1 -1
- package/commonjs/read/dropEmptyColumns.test.js.map +1 -1
- package/commonjs/read/dropEmptyRows.js +11 -23
- package/commonjs/read/dropEmptyRows.js.map +1 -1
- package/commonjs/read/dropEmptyRows.test.js.map +1 -1
- package/commonjs/read/getData.js +31 -43
- package/commonjs/read/getData.js.map +1 -1
- package/commonjs/read/isDateTimestamp.js +51 -40
- package/commonjs/read/isDateTimestamp.js.map +1 -1
- package/commonjs/read/parseCell.js +3 -10
- package/commonjs/read/parseCell.js.map +1 -1
- package/commonjs/read/parseCellValue.js +28 -59
- package/commonjs/read/parseCellValue.js.map +1 -1
- package/commonjs/read/parseCells.js +3 -7
- package/commonjs/read/parseCells.js.map +1 -1
- package/commonjs/read/parseDate.js +5 -5
- package/commonjs/read/parseDate.js.map +1 -1
- package/commonjs/read/parseDate.test.js.map +1 -1
- package/commonjs/read/parseDimensions.js +6 -18
- package/commonjs/read/parseDimensions.js.map +1 -1
- package/commonjs/read/parseFilePaths.js +4 -11
- package/commonjs/read/parseFilePaths.js.map +1 -1
- package/commonjs/read/parseProperties.js +6 -8
- package/commonjs/read/parseProperties.js.map +1 -1
- package/commonjs/read/parseSharedStrings.js +0 -3
- package/commonjs/read/parseSharedStrings.js.map +1 -1
- package/commonjs/read/parseSheet.js +3 -7
- package/commonjs/read/parseSheet.js.map +1 -1
- package/commonjs/read/parseStyles.js +13 -21
- package/commonjs/read/parseStyles.js.map +1 -1
- package/commonjs/read/readSheetNamesBrowser.js +0 -3
- package/commonjs/read/readSheetNamesBrowser.js.map +1 -1
- package/commonjs/read/readSheetNamesNode.js +0 -3
- package/commonjs/read/readSheetNamesNode.js.map +1 -1
- package/commonjs/read/readSheetNamesNode.test.js.map +1 -1
- package/commonjs/read/readSheetNamesWebWorker.js +0 -3
- package/commonjs/read/readSheetNamesWebWorker.js.map +1 -1
- package/commonjs/read/readXlsx.js +34 -42
- package/commonjs/read/readXlsx.js.map +1 -1
- package/commonjs/read/readXlsxFileBrowser.js +0 -5
- package/commonjs/read/readXlsxFileBrowser.js.map +1 -1
- package/commonjs/read/readXlsxFileContents.js +12 -22
- package/commonjs/read/readXlsxFileContents.js.map +1 -1
- package/commonjs/read/readXlsxFileNode.js +0 -5
- package/commonjs/read/readXlsxFileNode.js.map +1 -1
- package/commonjs/read/readXlsxFileNode.test.js.map +1 -1
- package/commonjs/read/readXlsxFileWebWorker.js +0 -5
- package/commonjs/read/readXlsxFileWebWorker.js.map +1 -1
- package/commonjs/read/schema/convertMapToSchema.js +1 -8
- package/commonjs/read/schema/convertMapToSchema.js.map +1 -1
- package/commonjs/read/schema/convertMapToSchema.test.js.map +1 -1
- package/commonjs/read/schema/convertToJson.js +143 -142
- package/commonjs/read/schema/convertToJson.js.map +1 -1
- package/commonjs/read/schema/convertToJson.legacy.js +60 -0
- package/commonjs/read/schema/convertToJson.legacy.js.map +1 -0
- package/commonjs/read/schema/convertToJson.legacy.test.js.map +1 -0
- package/commonjs/read/schema/convertToJson.spreadsheet.js +25 -0
- package/commonjs/read/schema/convertToJson.spreadsheet.js.map +1 -0
- package/commonjs/read/schema/convertToJson.spreadsheet.test.js.map +1 -0
- package/commonjs/read/schema/convertToJson.test.js.map +1 -1
- package/commonjs/read/unpackXlsxFileBrowser.js +3 -9
- package/commonjs/read/unpackXlsxFileBrowser.js.map +1 -1
- package/commonjs/read/unpackXlsxFileNode.js +9 -15
- package/commonjs/read/unpackXlsxFileNode.js.map +1 -1
- package/commonjs/types/Boolean.js +0 -4
- package/commonjs/types/Boolean.js.map +1 -1
- package/commonjs/types/Date.js +0 -12
- package/commonjs/types/Date.js.map +1 -1
- package/commonjs/types/Email.js +0 -7
- package/commonjs/types/Email.js.map +1 -1
- package/commonjs/types/Email.test.js.map +1 -1
- package/commonjs/types/Integer.js +0 -7
- package/commonjs/types/Integer.js.map +1 -1
- package/commonjs/types/Integer.test.js.map +1 -1
- package/commonjs/types/InvalidError.js +8 -28
- package/commonjs/types/InvalidError.js.map +1 -1
- package/commonjs/types/Number.js +2 -10
- package/commonjs/types/Number.js.map +1 -1
- package/commonjs/types/String.js +4 -11
- package/commonjs/types/String.js.map +1 -1
- package/commonjs/types/URL.js +5 -8
- package/commonjs/types/URL.js.map +1 -1
- package/commonjs/types/URL.test.js.map +1 -1
- package/commonjs/xml/dom.js +6 -25
- package/commonjs/xml/dom.js.map +1 -1
- package/commonjs/xml/xlsx.js +1 -24
- package/commonjs/xml/xlsx.js.map +1 -1
- package/commonjs/xml/xml.js +1 -4
- package/commonjs/xml/xml.js.map +1 -1
- package/commonjs/xml/xmlBrowser.js +1 -2
- package/commonjs/xml/xmlBrowser.js.map +1 -1
- package/commonjs/xml/xpath/xlsx-xpath.js +3 -16
- package/commonjs/xml/xpath/xlsx-xpath.js.map +1 -1
- package/commonjs/xml/xpath/xpathBrowser.js +3 -5
- package/commonjs/xml/xpath/xpathBrowser.js.map +1 -1
- package/commonjs/xml/xpath/xpathNode.js +1 -5
- package/commonjs/xml/xpath/xpathNode.js.map +1 -1
- package/map/index.cjs +2 -0
- package/map/index.cjs.js +7 -0
- package/map/index.d.ts +11 -0
- package/map/index.js +1 -0
- package/map/package.json +17 -0
- package/modules/read/coordinates.js +7 -8
- package/modules/read/coordinates.js.map +1 -1
- package/modules/read/dropEmptyColumns.js +6 -17
- package/modules/read/dropEmptyColumns.js.map +1 -1
- package/modules/read/dropEmptyColumns.test.js.map +1 -1
- package/modules/read/dropEmptyRows.js +11 -22
- package/modules/read/dropEmptyRows.js.map +1 -1
- package/modules/read/dropEmptyRows.test.js.map +1 -1
- package/modules/read/getData.js +31 -39
- package/modules/read/getData.js.map +1 -1
- package/modules/read/isDateTimestamp.js +52 -39
- package/modules/read/isDateTimestamp.js.map +1 -1
- package/modules/read/parseCell.js +6 -6
- package/modules/read/parseCell.js.map +1 -1
- package/modules/read/parseCellValue.js +30 -55
- package/modules/read/parseCellValue.js.map +1 -1
- package/modules/read/parseCells.js +3 -3
- package/modules/read/parseCells.js.map +1 -1
- package/modules/read/parseDate.js +5 -4
- package/modules/read/parseDate.js.map +1 -1
- package/modules/read/parseDate.test.js.map +1 -1
- package/modules/read/parseDimensions.js +9 -17
- package/modules/read/parseDimensions.js.map +1 -1
- package/modules/read/parseFilePaths.js +5 -10
- package/modules/read/parseFilePaths.js.map +1 -1
- package/modules/read/parseProperties.js +8 -7
- package/modules/read/parseProperties.js.map +1 -1
- package/modules/read/parseSharedStrings.js +0 -1
- package/modules/read/parseSharedStrings.js.map +1 -1
- package/modules/read/parseSheet.js +3 -2
- package/modules/read/parseSheet.js.map +1 -1
- package/modules/read/parseStyles.js +16 -21
- package/modules/read/parseStyles.js.map +1 -1
- package/modules/read/readSheetNamesBrowser.js +1 -1
- package/modules/read/readSheetNamesBrowser.js.map +1 -1
- package/modules/read/readSheetNamesNode.js +1 -1
- package/modules/read/readSheetNamesNode.js.map +1 -1
- package/modules/read/readSheetNamesNode.test.js.map +1 -1
- package/modules/read/readSheetNamesWebWorker.js +1 -1
- package/modules/read/readSheetNamesWebWorker.js.map +1 -1
- package/modules/read/readXlsx.js +37 -35
- package/modules/read/readXlsx.js.map +1 -1
- package/modules/read/readXlsxFileBrowser.js +1 -1
- package/modules/read/readXlsxFileBrowser.js.map +1 -1
- package/modules/read/readXlsxFileContents.js +12 -17
- package/modules/read/readXlsxFileContents.js.map +1 -1
- package/modules/read/readXlsxFileNode.js +1 -1
- package/modules/read/readXlsxFileNode.js.map +1 -1
- package/modules/read/readXlsxFileNode.test.js.map +1 -1
- package/modules/read/readXlsxFileWebWorker.js +1 -1
- package/modules/read/readXlsxFileWebWorker.js.map +1 -1
- package/modules/read/schema/convertMapToSchema.js +1 -7
- package/modules/read/schema/convertMapToSchema.js.map +1 -1
- package/modules/read/schema/convertMapToSchema.test.js.map +1 -1
- package/modules/read/schema/convertToJson.js +143 -133
- package/modules/read/schema/convertToJson.js.map +1 -1
- package/modules/read/schema/convertToJson.legacy.js +53 -0
- package/modules/read/schema/convertToJson.legacy.js.map +1 -0
- package/modules/read/schema/convertToJson.legacy.test.js.map +1 -0
- package/modules/read/schema/convertToJson.spreadsheet.js +19 -0
- package/modules/read/schema/convertToJson.spreadsheet.js.map +1 -0
- package/modules/read/schema/convertToJson.spreadsheet.test.js.map +1 -0
- package/modules/read/schema/convertToJson.test.js.map +1 -1
- package/modules/read/unpackXlsxFileBrowser.js +4 -7
- package/modules/read/unpackXlsxFileBrowser.js.map +1 -1
- package/modules/read/unpackXlsxFileNode.js +9 -7
- package/modules/read/unpackXlsxFileNode.js.map +1 -1
- package/modules/types/Boolean.js +0 -1
- package/modules/types/Boolean.js.map +1 -1
- package/modules/types/Date.js +0 -8
- package/modules/types/Date.js.map +1 -1
- package/modules/types/Email.js +0 -2
- package/modules/types/Email.js.map +1 -1
- package/modules/types/Email.test.js.map +1 -1
- package/modules/types/Integer.js +0 -2
- package/modules/types/Integer.js.map +1 -1
- package/modules/types/Integer.test.js.map +1 -1
- package/modules/types/InvalidError.js +7 -25
- package/modules/types/InvalidError.js.map +1 -1
- package/modules/types/Number.js +2 -7
- package/modules/types/Number.js.map +1 -1
- package/modules/types/String.js +4 -8
- package/modules/types/String.js.map +1 -1
- package/modules/types/URL.js +5 -4
- package/modules/types/URL.js.map +1 -1
- package/modules/types/URL.test.js.map +1 -1
- package/modules/xml/dom.js +6 -18
- package/modules/xml/dom.js.map +1 -1
- package/modules/xml/xlsx.js +4 -13
- package/modules/xml/xlsx.js.map +1 -1
- package/modules/xml/xml.js.map +1 -1
- package/modules/xml/xmlBrowser.js.map +1 -1
- package/modules/xml/xpath/xlsx-xpath.js +2 -1
- package/modules/xml/xpath/xlsx-xpath.js.map +1 -1
- package/modules/xml/xpath/xpathBrowser.js +3 -4
- package/modules/xml/xpath/xpathBrowser.js.map +1 -1
- package/modules/xml/xpath/xpathNode.js +1 -0
- package/modules/xml/xpath/xpathNode.js.map +1 -1
- package/package.json +6 -1
- package/schema/index.cjs +2 -2
- package/schema/index.cjs.js +2 -2
- package/schema/index.d.ts +7 -2
- package/schema/index.js +1 -1
- package/types.d.ts +25 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getRelationships } from '../xml/xlsx.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Returns sheet file paths.
|
|
4
5
|
* Seems that the correct place to look for the `sheetId` -> `filename` mapping
|
|
@@ -8,7 +9,6 @@ import { getRelationships } from '../xml/xlsx.js';
|
|
|
8
9
|
* @param {object} xml
|
|
9
10
|
* @return {object}
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
12
|
export default function parseFilePaths(content, xml) {
|
|
13
13
|
// Example:
|
|
14
14
|
// <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
@@ -24,27 +24,24 @@ export default function parseFilePaths(content, xml) {
|
|
|
24
24
|
sharedStrings: undefined,
|
|
25
25
|
styles: undefined
|
|
26
26
|
};
|
|
27
|
-
|
|
28
27
|
var addFilePathInfo = function addFilePathInfo(relationship) {
|
|
29
28
|
var filePath = relationship.getAttribute('Target');
|
|
30
29
|
var fileType = relationship.getAttribute('Type');
|
|
31
|
-
|
|
32
30
|
switch (fileType) {
|
|
33
31
|
case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles':
|
|
34
32
|
filePaths.styles = getFilePath(filePath);
|
|
35
33
|
break;
|
|
36
|
-
|
|
37
34
|
case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings':
|
|
38
35
|
filePaths.sharedStrings = getFilePath(filePath);
|
|
39
36
|
break;
|
|
40
|
-
|
|
41
37
|
case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet':
|
|
42
38
|
filePaths.sheets[relationship.getAttribute('Id')] = getFilePath(filePath);
|
|
43
39
|
break;
|
|
44
40
|
}
|
|
45
41
|
};
|
|
42
|
+
getRelationships(document).forEach(addFilePathInfo);
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
// Seems like "sharedStrings.xml" is not required to exist.
|
|
48
45
|
// For example, when the spreadsheet doesn't contain any strings.
|
|
49
46
|
// https://github.com/catamphetamine/read-excel-file/issues/85
|
|
50
47
|
// if (!filePaths.sharedStrings) {
|
|
@@ -53,7 +50,6 @@ export default function parseFilePaths(content, xml) {
|
|
|
53
50
|
|
|
54
51
|
return filePaths;
|
|
55
52
|
}
|
|
56
|
-
|
|
57
53
|
function getFilePath(path) {
|
|
58
54
|
// Normally, `path` is a relative path inside the ZIP archive,
|
|
59
55
|
// like "worksheets/sheet1.xml", or "sharedStrings.xml", or "styles.xml".
|
|
@@ -64,13 +60,12 @@ function getFilePath(path) {
|
|
|
64
60
|
// seem to support such absolute file paths, so this library does too.
|
|
65
61
|
if (path[0] === '/') {
|
|
66
62
|
return path.slice('/'.length);
|
|
67
|
-
}
|
|
63
|
+
}
|
|
64
|
+
// // Seems like a path could also be a URL.
|
|
68
65
|
// // http://officeopenxml.com/anatomyofOOXML-xlsx.php
|
|
69
66
|
// if (/^[a-z]+\:\/\//.test(path)) {
|
|
70
67
|
// return path
|
|
71
68
|
// }
|
|
72
|
-
|
|
73
|
-
|
|
74
69
|
return 'xl/' + path;
|
|
75
70
|
}
|
|
76
71
|
//# sourceMappingURL=parseFilePaths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseFilePaths.js","names":["getRelationships","parseFilePaths","content","xml","document","createDocument","filePaths","sheets","sharedStrings","undefined","styles","addFilePathInfo","relationship","filePath","getAttribute","fileType","getFilePath","forEach","path","slice","length"],"sources":["../../source/read/parseFilePaths.js"],"sourcesContent":["import {\r\n getRelationships\r\n} from '../xml/xlsx.js'\r\n\r\n/**\r\n * Returns sheet file paths.\r\n * Seems that the correct place to look for the `sheetId` -> `filename` mapping\r\n * is `xl/_rels/workbook.xml.rels` file.\r\n * https://github.com/tidyverse/readxl/issues/104\r\n * @param {string} content — `xl/_rels/workbook.xml.rels` file contents.\r\n * @param {object} xml\r\n * @return {object}\r\n */\r\nexport default function parseFilePaths(content, xml) {\r\n // Example:\r\n // <Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\r\n // ...\r\n // <Relationship\r\n // Id=\"rId3\"\r\n // Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\"\r\n // Target=\"worksheets/sheet1.xml\"/>\r\n // </Relationships>\r\n const document = xml.createDocument(content)\r\n\r\n const filePaths = {\r\n sheets: {},\r\n sharedStrings: undefined,\r\n styles: undefined\r\n }\r\n\r\n const addFilePathInfo = (relationship) => {\r\n const filePath = relationship.getAttribute('Target')\r\n const fileType = relationship.getAttribute('Type')\r\n switch (fileType) {\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles':\r\n filePaths.styles = getFilePath(filePath)\r\n break\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings':\r\n filePaths.sharedStrings = getFilePath(filePath)\r\n break\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet':\r\n filePaths.sheets[relationship.getAttribute('Id')] = getFilePath(filePath)\r\n break\r\n }\r\n }\r\n\r\n getRelationships(document).forEach(addFilePathInfo)\r\n\r\n // Seems like \"sharedStrings.xml\" is not required to exist.\r\n // For example, when the spreadsheet doesn't contain any strings.\r\n // https://github.com/catamphetamine/read-excel-file/issues/85\r\n // if (!filePaths.sharedStrings) {\r\n // throw new Error('\"sharedStrings.xml\" file not found in the *.xlsx file')\r\n // }\r\n\r\n return filePaths\r\n}\r\n\r\nfunction getFilePath(path) {\r\n // Normally, `path` is a relative path inside the ZIP archive,\r\n // like \"worksheets/sheet1.xml\", or \"sharedStrings.xml\", or \"styles.xml\".\r\n // There has been one weird case when file path was an absolute path,\r\n // like \"/xl/worksheets/sheet1.xml\" (specifically for sheets):\r\n // https://github.com/catamphetamine/read-excel-file/pull/95\r\n // Other libraries (like `xlsx`) and software (like Google Docs)\r\n // seem to support such absolute file paths, so this library does too.\r\n if (path[0] === '/') {\r\n return path.slice('/'.length)\r\n }\r\n // // Seems like a path could also be a URL.\r\n // // http://officeopenxml.com/anatomyofOOXML-xlsx.php\r\n // if (/^[a-z]+\\:\\/\\//.test(path)) {\r\n // return path\r\n // }\r\n return 'xl/' + path\r\n}"],"mappings":"AAAA,SACEA,
|
|
1
|
+
{"version":3,"file":"parseFilePaths.js","names":["getRelationships","parseFilePaths","content","xml","document","createDocument","filePaths","sheets","sharedStrings","undefined","styles","addFilePathInfo","relationship","filePath","getAttribute","fileType","getFilePath","forEach","path","slice","length"],"sources":["../../source/read/parseFilePaths.js"],"sourcesContent":["import {\r\n getRelationships\r\n} from '../xml/xlsx.js'\r\n\r\n/**\r\n * Returns sheet file paths.\r\n * Seems that the correct place to look for the `sheetId` -> `filename` mapping\r\n * is `xl/_rels/workbook.xml.rels` file.\r\n * https://github.com/tidyverse/readxl/issues/104\r\n * @param {string} content — `xl/_rels/workbook.xml.rels` file contents.\r\n * @param {object} xml\r\n * @return {object}\r\n */\r\nexport default function parseFilePaths(content, xml) {\r\n // Example:\r\n // <Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\r\n // ...\r\n // <Relationship\r\n // Id=\"rId3\"\r\n // Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\"\r\n // Target=\"worksheets/sheet1.xml\"/>\r\n // </Relationships>\r\n const document = xml.createDocument(content)\r\n\r\n const filePaths = {\r\n sheets: {},\r\n sharedStrings: undefined,\r\n styles: undefined\r\n }\r\n\r\n const addFilePathInfo = (relationship) => {\r\n const filePath = relationship.getAttribute('Target')\r\n const fileType = relationship.getAttribute('Type')\r\n switch (fileType) {\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles':\r\n filePaths.styles = getFilePath(filePath)\r\n break\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings':\r\n filePaths.sharedStrings = getFilePath(filePath)\r\n break\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet':\r\n filePaths.sheets[relationship.getAttribute('Id')] = getFilePath(filePath)\r\n break\r\n }\r\n }\r\n\r\n getRelationships(document).forEach(addFilePathInfo)\r\n\r\n // Seems like \"sharedStrings.xml\" is not required to exist.\r\n // For example, when the spreadsheet doesn't contain any strings.\r\n // https://github.com/catamphetamine/read-excel-file/issues/85\r\n // if (!filePaths.sharedStrings) {\r\n // throw new Error('\"sharedStrings.xml\" file not found in the *.xlsx file')\r\n // }\r\n\r\n return filePaths\r\n}\r\n\r\nfunction getFilePath(path) {\r\n // Normally, `path` is a relative path inside the ZIP archive,\r\n // like \"worksheets/sheet1.xml\", or \"sharedStrings.xml\", or \"styles.xml\".\r\n // There has been one weird case when file path was an absolute path,\r\n // like \"/xl/worksheets/sheet1.xml\" (specifically for sheets):\r\n // https://github.com/catamphetamine/read-excel-file/pull/95\r\n // Other libraries (like `xlsx`) and software (like Google Docs)\r\n // seem to support such absolute file paths, so this library does too.\r\n if (path[0] === '/') {\r\n return path.slice('/'.length)\r\n }\r\n // // Seems like a path could also be a URL.\r\n // // http://officeopenxml.com/anatomyofOOXML-xlsx.php\r\n // if (/^[a-z]+\\:\\/\\//.test(path)) {\r\n // return path\r\n // }\r\n return 'xl/' + path\r\n}"],"mappings":"AAAA,SACEA,gBAAgB,QACX,gBAAgB;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAcA,CAACC,OAAO,EAAEC,GAAG,EAAE;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAMC,QAAQ,GAAGD,GAAG,CAACE,cAAc,CAACH,OAAO,CAAC;EAE5C,IAAMI,SAAS,GAAG;IAChBC,MAAM,EAAE,CAAC,CAAC;IACVC,aAAa,EAAEC,SAAS;IACxBC,MAAM,EAAED;EACV,CAAC;EAED,IAAME,eAAe,GAAG,SAAlBA,eAAeA,CAAIC,YAAY,EAAK;IACxC,IAAMC,QAAQ,GAAGD,YAAY,CAACE,YAAY,CAAC,QAAQ,CAAC;IACpD,IAAMC,QAAQ,GAAGH,YAAY,CAACE,YAAY,CAAC,MAAM,CAAC;IAClD,QAAQC,QAAQ;MACd,KAAK,4EAA4E;QAC/ET,SAAS,CAACI,MAAM,GAAGM,WAAW,CAACH,QAAQ,CAAC;QACxC;MACF,KAAK,mFAAmF;QACtFP,SAAS,CAACE,aAAa,GAAGQ,WAAW,CAACH,QAAQ,CAAC;QAC/C;MACF,KAAK,+EAA+E;QAClFP,SAAS,CAACC,MAAM,CAACK,YAAY,CAACE,YAAY,CAAC,IAAI,CAAC,CAAC,GAAGE,WAAW,CAACH,QAAQ,CAAC;QACzE;IACJ;EACF,CAAC;EAEDb,gBAAgB,CAACI,QAAQ,CAAC,CAACa,OAAO,CAACN,eAAe,CAAC;;EAEnD;EACA;EACA;EACA;EACA;EACA;;EAEA,OAAOL,SAAS;AAClB;AAEA,SAASU,WAAWA,CAACE,IAAI,EAAE;EACzB;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAIA,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IACnB,OAAOA,IAAI,CAACC,KAAK,CAAC,GAAG,CAACC,MAAM,CAAC;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,KAAK,GAAGF,IAAI;AACrB"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { getWorkbookProperties, getSheets } from '../xml/xlsx.js';
|
|
1
|
+
import { getWorkbookProperties, getSheets } from '../xml/xlsx.js';
|
|
2
2
|
|
|
3
|
+
// I guess `xl/workbook.xml` file should always be present inside the *.xlsx archive.
|
|
3
4
|
export default function parseProperties(content, xml) {
|
|
4
5
|
var book = xml.createDocument(content);
|
|
5
|
-
var properties = {};
|
|
6
|
+
var properties = {};
|
|
7
|
+
|
|
8
|
+
// Read `<workbookPr/>` element to detect whether dates are 1900-based or 1904-based.
|
|
6
9
|
// https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel
|
|
7
10
|
// http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/workbookPr.html
|
|
8
11
|
|
|
9
12
|
var workbookProperties = getWorkbookProperties(book);
|
|
10
|
-
|
|
11
13
|
if (workbookProperties && workbookProperties.getAttribute('date1904') === '1') {
|
|
12
14
|
properties.epoch1904 = true;
|
|
13
|
-
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Get sheets info (indexes, names, if they're available).
|
|
14
18
|
// Example:
|
|
15
19
|
// <sheets>
|
|
16
20
|
// <sheet
|
|
@@ -21,9 +25,7 @@ export default function parseProperties(content, xml) {
|
|
|
21
25
|
// </sheets>
|
|
22
26
|
// http://www.datypic.com/sc/ooxml/e-ssml_sheet-1.html
|
|
23
27
|
|
|
24
|
-
|
|
25
28
|
properties.sheets = [];
|
|
26
|
-
|
|
27
29
|
var addSheetInfo = function addSheetInfo(sheet) {
|
|
28
30
|
if (sheet.getAttribute('name')) {
|
|
29
31
|
properties.sheets.push({
|
|
@@ -33,7 +35,6 @@ export default function parseProperties(content, xml) {
|
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
|
-
|
|
37
38
|
getSheets(book).forEach(addSheetInfo);
|
|
38
39
|
return properties;
|
|
39
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseProperties.js","names":["getWorkbookProperties","getSheets","parseProperties","content","xml","book","createDocument","properties","workbookProperties","getAttribute","epoch1904","sheets","addSheetInfo","sheet","push","id","name","relationId","forEach"],"sources":["../../source/read/parseProperties.js"],"sourcesContent":["import {\r\n getWorkbookProperties,\r\n getSheets\r\n} from '../xml/xlsx.js'\r\n\r\n// I guess `xl/workbook.xml` file should always be present inside the *.xlsx archive.\r\nexport default function parseProperties(content, xml) {\r\n const book = xml.createDocument(content)\r\n\r\n const properties = {};\r\n\r\n // Read `<workbookPr/>` element to detect whether dates are 1900-based or 1904-based.\r\n // https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/workbookPr.html\r\n\r\n const workbookProperties = getWorkbookProperties(book)\r\n\r\n if (workbookProperties && workbookProperties.getAttribute('date1904') === '1') {\r\n properties.epoch1904 = true\r\n }\r\n\r\n // Get sheets info (indexes, names, if they're available).\r\n // Example:\r\n // <sheets>\r\n // <sheet\r\n // xmlns:ns=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"\r\n // name=\"Sheet1\"\r\n // sheetId=\"1\"\r\n // ns:id=\"rId3\"/>\r\n // </sheets>\r\n // http://www.datypic.com/sc/ooxml/e-ssml_sheet-1.html\r\n\r\n properties.sheets = []\r\n\r\n const addSheetInfo = (sheet) => {\r\n if (sheet.getAttribute('name')) {\r\n properties.sheets.push({\r\n id: sheet.getAttribute('sheetId'),\r\n name: sheet.getAttribute('name'),\r\n relationId: sheet.getAttribute('r:id')\r\n })\r\n }\r\n }\r\n\r\n getSheets(book).forEach(addSheetInfo)\r\n\r\n return properties;\r\n}"],"mappings":"AAAA,SACEA,
|
|
1
|
+
{"version":3,"file":"parseProperties.js","names":["getWorkbookProperties","getSheets","parseProperties","content","xml","book","createDocument","properties","workbookProperties","getAttribute","epoch1904","sheets","addSheetInfo","sheet","push","id","name","relationId","forEach"],"sources":["../../source/read/parseProperties.js"],"sourcesContent":["import {\r\n getWorkbookProperties,\r\n getSheets\r\n} from '../xml/xlsx.js'\r\n\r\n// I guess `xl/workbook.xml` file should always be present inside the *.xlsx archive.\r\nexport default function parseProperties(content, xml) {\r\n const book = xml.createDocument(content)\r\n\r\n const properties = {};\r\n\r\n // Read `<workbookPr/>` element to detect whether dates are 1900-based or 1904-based.\r\n // https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/workbookPr.html\r\n\r\n const workbookProperties = getWorkbookProperties(book)\r\n\r\n if (workbookProperties && workbookProperties.getAttribute('date1904') === '1') {\r\n properties.epoch1904 = true\r\n }\r\n\r\n // Get sheets info (indexes, names, if they're available).\r\n // Example:\r\n // <sheets>\r\n // <sheet\r\n // xmlns:ns=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"\r\n // name=\"Sheet1\"\r\n // sheetId=\"1\"\r\n // ns:id=\"rId3\"/>\r\n // </sheets>\r\n // http://www.datypic.com/sc/ooxml/e-ssml_sheet-1.html\r\n\r\n properties.sheets = []\r\n\r\n const addSheetInfo = (sheet) => {\r\n if (sheet.getAttribute('name')) {\r\n properties.sheets.push({\r\n id: sheet.getAttribute('sheetId'),\r\n name: sheet.getAttribute('name'),\r\n relationId: sheet.getAttribute('r:id')\r\n })\r\n }\r\n }\r\n\r\n getSheets(book).forEach(addSheetInfo)\r\n\r\n return properties;\r\n}"],"mappings":"AAAA,SACEA,qBAAqB,EACrBC,SAAS,QACJ,gBAAgB;;AAEvB;AACA,eAAe,SAASC,eAAeA,CAACC,OAAO,EAAEC,GAAG,EAAE;EACpD,IAAMC,IAAI,GAAGD,GAAG,CAACE,cAAc,CAACH,OAAO,CAAC;EAExC,IAAMI,UAAU,GAAG,CAAC,CAAC;;EAErB;EACA;EACA;;EAEA,IAAMC,kBAAkB,GAAGR,qBAAqB,CAACK,IAAI,CAAC;EAEtD,IAAIG,kBAAkB,IAAIA,kBAAkB,CAACC,YAAY,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE;IAC7EF,UAAU,CAACG,SAAS,GAAG,IAAI;EAC7B;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEAH,UAAU,CAACI,MAAM,GAAG,EAAE;EAEtB,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CAAIC,KAAK,EAAK;IAC9B,IAAIA,KAAK,CAACJ,YAAY,CAAC,MAAM,CAAC,EAAE;MAC9BF,UAAU,CAACI,MAAM,CAACG,IAAI,CAAC;QACrBC,EAAE,EAAEF,KAAK,CAACJ,YAAY,CAAC,SAAS,CAAC;QACjCO,IAAI,EAAEH,KAAK,CAACJ,YAAY,CAAC,MAAM,CAAC;QAChCQ,UAAU,EAAEJ,KAAK,CAACJ,YAAY,CAAC,MAAM;MACvC,CAAC,CAAC;IACJ;EACF,CAAC;EAEDR,SAAS,CAACI,IAAI,CAAC,CAACa,OAAO,CAACN,YAAY,CAAC;EAErC,OAAOL,UAAU;AACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseSharedStrings.js","names":["getSharedStrings","parseSharedStrings","content","xml","createDocument"],"sources":["../../source/read/parseSharedStrings.js"],"sourcesContent":["import {\r\n getSharedStrings\r\n} from '../xml/xlsx.js'\r\n\r\nexport default function parseSharedStrings(content, xml) {\r\n if (!content) {\r\n return []\r\n }\r\n return getSharedStrings(xml.createDocument(content))\r\n}"],"mappings":"AAAA,SACEA,
|
|
1
|
+
{"version":3,"file":"parseSharedStrings.js","names":["getSharedStrings","parseSharedStrings","content","xml","createDocument"],"sources":["../../source/read/parseSharedStrings.js"],"sourcesContent":["import {\r\n getSharedStrings\r\n} from '../xml/xlsx.js'\r\n\r\nexport default function parseSharedStrings(content, xml) {\r\n if (!content) {\r\n return []\r\n }\r\n return getSharedStrings(xml.createDocument(content))\r\n}"],"mappings":"AAAA,SACEA,gBAAgB,QACX,gBAAgB;AAEvB,eAAe,SAASC,kBAAkBA,CAACC,OAAO,EAAEC,GAAG,EAAE;EACvD,IAAI,CAACD,OAAO,EAAE;IACZ,OAAO,EAAE;EACX;EACA,OAAOF,gBAAgB,CAACG,GAAG,CAACC,cAAc,CAACF,OAAO,CAAC,CAAC;AACtD"}
|
|
@@ -3,9 +3,10 @@ import parseDimensions from './parseDimensions.js';
|
|
|
3
3
|
import { calculateDimensions } from './coordinates.js';
|
|
4
4
|
export default function parseSheet(content, xml, values, styles, properties, options) {
|
|
5
5
|
var sheet = xml.createDocument(content);
|
|
6
|
-
var cells = parseCells(sheet, xml, values, styles, properties, options);
|
|
7
|
-
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
|
|
6
|
+
var cells = parseCells(sheet, xml, values, styles, properties, options);
|
|
8
7
|
|
|
8
|
+
// `dimensions` defines the spreadsheet area containing all non-empty cells.
|
|
9
|
+
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
|
|
9
10
|
var dimensions = parseDimensions(sheet) || calculateDimensions(cells);
|
|
10
11
|
return {
|
|
11
12
|
cells: cells,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseSheet.js","names":["parseCells","parseDimensions","calculateDimensions","parseSheet","content","xml","values","styles","properties","options","sheet","createDocument","cells","dimensions"],"sources":["../../source/read/parseSheet.js"],"sourcesContent":["import parseCells from './parseCells.js'\r\nimport parseDimensions from './parseDimensions.js'\r\n\r\nimport { calculateDimensions } from './coordinates.js'\r\n\r\nexport default function parseSheet(content, xml, values, styles, properties, options) {\r\n const sheet = xml.createDocument(content)\r\n\r\n const cells = parseCells(sheet, xml, values, styles, properties, options)\r\n\r\n // `dimensions` defines the spreadsheet area containing all non-empty cells.\r\n // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1\r\n const dimensions = parseDimensions(sheet) || calculateDimensions(cells)\r\n\r\n return { cells, dimensions }\r\n}"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"parseSheet.js","names":["parseCells","parseDimensions","calculateDimensions","parseSheet","content","xml","values","styles","properties","options","sheet","createDocument","cells","dimensions"],"sources":["../../source/read/parseSheet.js"],"sourcesContent":["import parseCells from './parseCells.js'\r\nimport parseDimensions from './parseDimensions.js'\r\n\r\nimport { calculateDimensions } from './coordinates.js'\r\n\r\nexport default function parseSheet(content, xml, values, styles, properties, options) {\r\n const sheet = xml.createDocument(content)\r\n\r\n const cells = parseCells(sheet, xml, values, styles, properties, options)\r\n\r\n // `dimensions` defines the spreadsheet area containing all non-empty cells.\r\n // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1\r\n const dimensions = parseDimensions(sheet) || calculateDimensions(cells)\r\n\r\n return { cells, dimensions }\r\n}"],"mappings":"AAAA,OAAOA,UAAU,MAAM,iBAAiB;AACxC,OAAOC,eAAe,MAAM,sBAAsB;AAElD,SAASC,mBAAmB,QAAQ,kBAAkB;AAEtD,eAAe,SAASC,UAAUA,CAACC,OAAO,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAEC,OAAO,EAAE;EACpF,IAAMC,KAAK,GAAGL,GAAG,CAACM,cAAc,CAACP,OAAO,CAAC;EAEzC,IAAMQ,KAAK,GAAGZ,UAAU,CAACU,KAAK,EAAEL,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAEC,OAAO,CAAC;;EAEzE;EACA;EACA,IAAMI,UAAU,GAAGZ,eAAe,CAACS,KAAK,CAAC,IAAIR,mBAAmB,CAACU,KAAK,CAAC;EAEvE,OAAO;IAAEA,KAAK,EAALA,KAAK;IAAEC,UAAU,EAAVA;EAAW,CAAC;AAC9B"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
function _objectSpread(
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
import { getBaseStyles, getCellStyles, getNumberFormats } from '../xml/xlsx.js';
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
import { getBaseStyles, getCellStyles, getNumberFormats } from '../xml/xlsx.js';
|
|
8
|
+
|
|
9
|
+
// http://officeopenxml.com/SSstyles.php
|
|
8
10
|
// Returns an array of cell styles.
|
|
9
11
|
// A cell style index is its ID.
|
|
10
|
-
|
|
11
12
|
export default function parseStyles(content, xml) {
|
|
12
13
|
if (!content) {
|
|
13
14
|
return {};
|
|
14
|
-
}
|
|
15
|
-
// https://www.office-forums.com/threads/cellxfs-cellstylexfs.2163519/
|
|
16
|
-
|
|
15
|
+
}
|
|
17
16
|
|
|
17
|
+
// https://social.msdn.microsoft.com/Forums/sqlserver/en-US/708978af-b598-45c4-a598-d3518a5a09f0/howwhen-is-cellstylexfs-vs-cellxfs-applied-to-a-cell?forum=os_binaryfile
|
|
18
|
+
// https://www.office-forums.com/threads/cellxfs-cellstylexfs.2163519/
|
|
18
19
|
var doc = xml.createDocument(content);
|
|
19
20
|
var baseStyles = getBaseStyles(doc).map(parseCellStyle);
|
|
20
21
|
var numberFormats = getNumberFormats(doc).map(parseNumberFormatStyle).reduce(function (formats, format) {
|
|
@@ -23,33 +24,28 @@ export default function parseStyles(content, xml) {
|
|
|
23
24
|
formats[format.id] = format;
|
|
24
25
|
return formats;
|
|
25
26
|
}, []);
|
|
26
|
-
|
|
27
27
|
var getCellStyle = function getCellStyle(xf) {
|
|
28
28
|
if (xf.hasAttribute('xfId')) {
|
|
29
29
|
return _objectSpread(_objectSpread({}, baseStyles[xf.xfId]), parseCellStyle(xf, numberFormats));
|
|
30
30
|
}
|
|
31
|
-
|
|
32
31
|
return parseCellStyle(xf, numberFormats);
|
|
33
32
|
};
|
|
34
|
-
|
|
35
33
|
return getCellStyles(doc).map(getCellStyle);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
function parseNumberFormatStyle(numFmt) {
|
|
39
36
|
return {
|
|
40
37
|
id: numFmt.getAttribute('numFmtId'),
|
|
41
38
|
template: numFmt.getAttribute('formatCode')
|
|
42
39
|
};
|
|
43
|
-
}
|
|
44
|
-
|
|
40
|
+
}
|
|
45
41
|
|
|
42
|
+
// http://www.datypic.com/sc/ooxml/e-ssml_xf-2.html
|
|
46
43
|
function parseCellStyle(xf, numFmts) {
|
|
47
44
|
var style = {};
|
|
48
|
-
|
|
49
45
|
if (xf.hasAttribute('numFmtId')) {
|
|
50
|
-
var numberFormatId = xf.getAttribute('numFmtId');
|
|
46
|
+
var numberFormatId = xf.getAttribute('numFmtId');
|
|
47
|
+
// Built-in number formats don't have a `<numFmt/>` element in `styles.xml`.
|
|
51
48
|
// https://hexdocs.pm/xlsxir/number_styles.html
|
|
52
|
-
|
|
53
49
|
if (numFmts[numberFormatId]) {
|
|
54
50
|
style.numberFormat = numFmts[numberFormatId];
|
|
55
51
|
} else {
|
|
@@ -58,7 +54,6 @@ function parseCellStyle(xf, numFmts) {
|
|
|
58
54
|
};
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
|
-
|
|
62
57
|
return style;
|
|
63
58
|
}
|
|
64
59
|
//# sourceMappingURL=parseStyles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseStyles.js","names":["getBaseStyles","getCellStyles","getNumberFormats","parseStyles","content","xml","doc","createDocument","baseStyles","map","parseCellStyle","numberFormats","parseNumberFormatStyle","reduce","formats","format","id","getCellStyle","xf","hasAttribute","xfId","numFmt","getAttribute","template","numFmts","style","numberFormatId","numberFormat"],"sources":["../../source/read/parseStyles.js"],"sourcesContent":["import {\r\n getBaseStyles,\r\n getCellStyles,\r\n getNumberFormats\r\n} from '../xml/xlsx.js'\r\n\r\n// http://officeopenxml.com/SSstyles.php\r\n// Returns an array of cell styles.\r\n// A cell style index is its ID.\r\nexport default function parseStyles(content, xml) {\r\n if (!content) {\r\n return {}\r\n }\r\n\r\n // https://social.msdn.microsoft.com/Forums/sqlserver/en-US/708978af-b598-45c4-a598-d3518a5a09f0/howwhen-is-cellstylexfs-vs-cellxfs-applied-to-a-cell?forum=os_binaryfile\r\n // https://www.office-forums.com/threads/cellxfs-cellstylexfs.2163519/\r\n const doc = xml.createDocument(content)\r\n\r\n const baseStyles = getBaseStyles(doc)\r\n .map(parseCellStyle)\r\n\r\n const numberFormats = getNumberFormats(doc)\r\n .map(parseNumberFormatStyle)\r\n .reduce((formats, format) => {\r\n // Format ID is a numeric index.\r\n // There're some standard \"built-in\" formats (in Excel) up to about `100`.\r\n formats[format.id] = format\r\n return formats\r\n }, [])\r\n\r\n const getCellStyle = (xf) => {\r\n if (xf.hasAttribute('xfId')) {\r\n return {\r\n ...baseStyles[xf.xfId],\r\n ...parseCellStyle(xf, numberFormats)\r\n }\r\n }\r\n return parseCellStyle(xf, numberFormats)\r\n }\r\n\r\n return getCellStyles(doc).map(getCellStyle)\r\n}\r\n\r\nfunction parseNumberFormatStyle(numFmt) {\r\n return {\r\n id: numFmt.getAttribute('numFmtId'),\r\n template: numFmt.getAttribute('formatCode')\r\n }\r\n}\r\n\r\n// http://www.datypic.com/sc/ooxml/e-ssml_xf-2.html\r\nfunction parseCellStyle(xf, numFmts) {\r\n const style = {}\r\n if (xf.hasAttribute('numFmtId')) {\r\n const numberFormatId = xf.getAttribute('numFmtId')\r\n // Built-in number formats don't have a `<numFmt/>` element in `styles.xml`.\r\n // https://hexdocs.pm/xlsxir/number_styles.html\r\n if (numFmts[numberFormatId]) {\r\n style.numberFormat = numFmts[numberFormatId]\r\n } else {\r\n style.numberFormat = { id: numberFormatId }\r\n }\r\n }\r\n return style\r\n}"],"mappings":";;;;;;AAAA,SACEA,
|
|
1
|
+
{"version":3,"file":"parseStyles.js","names":["getBaseStyles","getCellStyles","getNumberFormats","parseStyles","content","xml","doc","createDocument","baseStyles","map","parseCellStyle","numberFormats","parseNumberFormatStyle","reduce","formats","format","id","getCellStyle","xf","hasAttribute","_objectSpread","xfId","numFmt","getAttribute","template","numFmts","style","numberFormatId","numberFormat"],"sources":["../../source/read/parseStyles.js"],"sourcesContent":["import {\r\n getBaseStyles,\r\n getCellStyles,\r\n getNumberFormats\r\n} from '../xml/xlsx.js'\r\n\r\n// http://officeopenxml.com/SSstyles.php\r\n// Returns an array of cell styles.\r\n// A cell style index is its ID.\r\nexport default function parseStyles(content, xml) {\r\n if (!content) {\r\n return {}\r\n }\r\n\r\n // https://social.msdn.microsoft.com/Forums/sqlserver/en-US/708978af-b598-45c4-a598-d3518a5a09f0/howwhen-is-cellstylexfs-vs-cellxfs-applied-to-a-cell?forum=os_binaryfile\r\n // https://www.office-forums.com/threads/cellxfs-cellstylexfs.2163519/\r\n const doc = xml.createDocument(content)\r\n\r\n const baseStyles = getBaseStyles(doc)\r\n .map(parseCellStyle)\r\n\r\n const numberFormats = getNumberFormats(doc)\r\n .map(parseNumberFormatStyle)\r\n .reduce((formats, format) => {\r\n // Format ID is a numeric index.\r\n // There're some standard \"built-in\" formats (in Excel) up to about `100`.\r\n formats[format.id] = format\r\n return formats\r\n }, [])\r\n\r\n const getCellStyle = (xf) => {\r\n if (xf.hasAttribute('xfId')) {\r\n return {\r\n ...baseStyles[xf.xfId],\r\n ...parseCellStyle(xf, numberFormats)\r\n }\r\n }\r\n return parseCellStyle(xf, numberFormats)\r\n }\r\n\r\n return getCellStyles(doc).map(getCellStyle)\r\n}\r\n\r\nfunction parseNumberFormatStyle(numFmt) {\r\n return {\r\n id: numFmt.getAttribute('numFmtId'),\r\n template: numFmt.getAttribute('formatCode')\r\n }\r\n}\r\n\r\n// http://www.datypic.com/sc/ooxml/e-ssml_xf-2.html\r\nfunction parseCellStyle(xf, numFmts) {\r\n const style = {}\r\n if (xf.hasAttribute('numFmtId')) {\r\n const numberFormatId = xf.getAttribute('numFmtId')\r\n // Built-in number formats don't have a `<numFmt/>` element in `styles.xml`.\r\n // https://hexdocs.pm/xlsxir/number_styles.html\r\n if (numFmts[numberFormatId]) {\r\n style.numberFormat = numFmts[numberFormatId]\r\n } else {\r\n style.numberFormat = { id: numberFormatId }\r\n }\r\n }\r\n return style\r\n}"],"mappings":";;;;;;AAAA,SACEA,aAAa,EACbC,aAAa,EACbC,gBAAgB,QACX,gBAAgB;;AAEvB;AACA;AACA;AACA,eAAe,SAASC,WAAWA,CAACC,OAAO,EAAEC,GAAG,EAAE;EAChD,IAAI,CAACD,OAAO,EAAE;IACZ,OAAO,CAAC,CAAC;EACX;;EAEA;EACA;EACA,IAAME,GAAG,GAAGD,GAAG,CAACE,cAAc,CAACH,OAAO,CAAC;EAEvC,IAAMI,UAAU,GAAGR,aAAa,CAACM,GAAG,CAAC,CAClCG,GAAG,CAACC,cAAc,CAAC;EAEtB,IAAMC,aAAa,GAAGT,gBAAgB,CAACI,GAAG,CAAC,CACxCG,GAAG,CAACG,sBAAsB,CAAC,CAC3BC,MAAM,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;IAC3B;IACA;IACAD,OAAO,CAACC,MAAM,CAACC,EAAE,CAAC,GAAGD,MAAM;IAC3B,OAAOD,OAAO;EAChB,CAAC,EAAE,EAAE,CAAC;EAER,IAAMG,YAAY,GAAG,SAAfA,YAAYA,CAAIC,EAAE,EAAK;IAC3B,IAAIA,EAAE,CAACC,YAAY,CAAC,MAAM,CAAC,EAAE;MAC3B,OAAAC,aAAA,CAAAA,aAAA,KACKZ,UAAU,CAACU,EAAE,CAACG,IAAI,CAAC,GACnBX,cAAc,CAACQ,EAAE,EAAEP,aAAa,CAAC;IAExC;IACA,OAAOD,cAAc,CAACQ,EAAE,EAAEP,aAAa,CAAC;EAC1C,CAAC;EAED,OAAOV,aAAa,CAACK,GAAG,CAAC,CAACG,GAAG,CAACQ,YAAY,CAAC;AAC7C;AAEA,SAASL,sBAAsBA,CAACU,MAAM,EAAE;EACtC,OAAO;IACLN,EAAE,EAAEM,MAAM,CAACC,YAAY,CAAC,UAAU,CAAC;IACnCC,QAAQ,EAAEF,MAAM,CAACC,YAAY,CAAC,YAAY;EAC5C,CAAC;AACH;;AAEA;AACA,SAASb,cAAcA,CAACQ,EAAE,EAAEO,OAAO,EAAE;EACnC,IAAMC,KAAK,GAAG,CAAC,CAAC;EAChB,IAAIR,EAAE,CAACC,YAAY,CAAC,UAAU,CAAC,EAAE;IAC/B,IAAMQ,cAAc,GAAGT,EAAE,CAACK,YAAY,CAAC,UAAU,CAAC;IAClD;IACA;IACA,IAAIE,OAAO,CAACE,cAAc,CAAC,EAAE;MAC3BD,KAAK,CAACE,YAAY,GAAGH,OAAO,CAACE,cAAc,CAAC;IAC9C,CAAC,MAAM;MACLD,KAAK,CAACE,YAAY,GAAG;QAAEZ,EAAE,EAAEW;MAAe,CAAC;IAC7C;EACF;EACA,OAAOD,KAAK;AACd"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import readXlsxFile from './readXlsxFileBrowser.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Reads the list of sheet names in an XLSX file in a web browser.
|
|
4
5
|
* @param {file} file - A file being uploaded in the browser.
|
|
5
6
|
* @return {Promise} Resolves to an array of objects of shape `{ name: string }`.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
8
|
export default function readSheetNames(file) {
|
|
9
9
|
return readXlsxFile(file, {
|
|
10
10
|
getSheets: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSheetNamesBrowser.js","names":["readXlsxFile","readSheetNames","file","getSheets","then","sheets","map","sheet","name"],"sources":["../../source/read/readSheetNamesBrowser.js"],"sourcesContent":["import readXlsxFile from './readXlsxFileBrowser.js'\r\n\r\n/**\r\n * Reads the list of sheet names in an XLSX file in a web browser.\r\n * @param {file} file - A file being uploaded in the browser.\r\n * @return {Promise} Resolves to an array of objects of shape `{ name: string }`.\r\n */\r\nexport default function readSheetNames(file) {\r\n\treturn readXlsxFile(file, { getSheets: true })\r\n\t\t.then(sheets => sheets.map(sheet => sheet.name))\r\n}"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"readSheetNamesBrowser.js","names":["readXlsxFile","readSheetNames","file","getSheets","then","sheets","map","sheet","name"],"sources":["../../source/read/readSheetNamesBrowser.js"],"sourcesContent":["import readXlsxFile from './readXlsxFileBrowser.js'\r\n\r\n/**\r\n * Reads the list of sheet names in an XLSX file in a web browser.\r\n * @param {file} file - A file being uploaded in the browser.\r\n * @return {Promise} Resolves to an array of objects of shape `{ name: string }`.\r\n */\r\nexport default function readSheetNames(file) {\r\n\treturn readXlsxFile(file, { getSheets: true })\r\n\t\t.then(sheets => sheets.map(sheet => sheet.name))\r\n}"],"mappings":"AAAA,OAAOA,YAAY,MAAM,0BAA0B;;AAEnD;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAcA,CAACC,IAAI,EAAE;EAC5C,OAAOF,YAAY,CAACE,IAAI,EAAE;IAAEC,SAAS,EAAE;EAAK,CAAC,CAAC,CAC5CC,IAAI,CAAC,UAAAC,MAAM;IAAA,OAAIA,MAAM,CAACC,GAAG,CAAC,UAAAC,KAAK;MAAA,OAAIA,KAAK,CAACC,IAAI;IAAA,EAAC;EAAA,EAAC;AAClD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import readXlsxFile from './readXlsxFileNode.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Reads the list of sheet names in an XLSX file in Node.js.
|
|
4
5
|
* @param {(string|Stream|Buffer)} input - A Node.js readable stream or a `Buffer` or a path to a file.
|
|
5
6
|
* @return {Promise} Resolves to an array of objects of shape `{ name: string }`.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
8
|
export default function readSheetNames(input) {
|
|
9
9
|
return readXlsxFile(input, {
|
|
10
10
|
getSheets: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSheetNamesNode.js","names":["readXlsxFile","readSheetNames","input","getSheets","then","sheets","map","sheet","name"],"sources":["../../source/read/readSheetNamesNode.js"],"sourcesContent":["import readXlsxFile from './readXlsxFileNode.js'\r\n\r\n/**\r\n * Reads the list of sheet names in an XLSX file in Node.js.\r\n * @param {(string|Stream|Buffer)} input - A Node.js readable stream or a `Buffer` or a path to a file.\r\n * @return {Promise} Resolves to an array of objects of shape `{ name: string }`.\r\n */\r\nexport default function readSheetNames(input) {\r\n\treturn readXlsxFile(input, { getSheets: true })\r\n\t\t.then(sheets => sheets.map(sheet => sheet.name))\r\n}"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"readSheetNamesNode.js","names":["readXlsxFile","readSheetNames","input","getSheets","then","sheets","map","sheet","name"],"sources":["../../source/read/readSheetNamesNode.js"],"sourcesContent":["import readXlsxFile from './readXlsxFileNode.js'\r\n\r\n/**\r\n * Reads the list of sheet names in an XLSX file in Node.js.\r\n * @param {(string|Stream|Buffer)} input - A Node.js readable stream or a `Buffer` or a path to a file.\r\n * @return {Promise} Resolves to an array of objects of shape `{ name: string }`.\r\n */\r\nexport default function readSheetNames(input) {\r\n\treturn readXlsxFile(input, { getSheets: true })\r\n\t\t.then(sheets => sheets.map(sheet => sheet.name))\r\n}"],"mappings":"AAAA,OAAOA,YAAY,MAAM,uBAAuB;;AAEhD;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAcA,CAACC,KAAK,EAAE;EAC7C,OAAOF,YAAY,CAACE,KAAK,EAAE;IAAEC,SAAS,EAAE;EAAK,CAAC,CAAC,CAC7CC,IAAI,CAAC,UAAAC,MAAM;IAAA,OAAIA,MAAM,CAACC,GAAG,CAAC,UAAAC,KAAK;MAAA,OAAIA,KAAK,CAACC,IAAI;IAAA,EAAC;EAAA,EAAC;AAClD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSheetNamesNode.test.js","names":["path","readSheetNamesNode","describe","it","resolve","then","sheetNames","should","deep","equal"],"sources":["../../source/read/readSheetNamesNode.test.js"],"sourcesContent":["import path from 'path'\r\n\r\nimport readSheetNamesNode from './readSheetNamesNode.js'\r\n\r\ndescribe('readSheetNamesNode', () => {\r\n\tit('should read the list of sheet names in an *.xlsx file in Node.js', () => {\r\n\t\treturn readSheetNamesNode(path.resolve('./test/spreadsheets/multiple-sheets.xlsx')).then((sheetNames) => {\r\n\t\t\tsheetNames.should.deep.equal(['sheet 1', 'sheet 2'])\r\n\t\t})\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"readSheetNamesNode.test.js","names":["path","readSheetNamesNode","describe","it","resolve","then","sheetNames","should","deep","equal"],"sources":["../../source/read/readSheetNamesNode.test.js"],"sourcesContent":["import path from 'path'\r\n\r\nimport readSheetNamesNode from './readSheetNamesNode.js'\r\n\r\ndescribe('readSheetNamesNode', () => {\r\n\tit('should read the list of sheet names in an *.xlsx file in Node.js', () => {\r\n\t\treturn readSheetNamesNode(path.resolve('./test/spreadsheets/multiple-sheets.xlsx')).then((sheetNames) => {\r\n\t\t\tsheetNames.should.deep.equal(['sheet 1', 'sheet 2'])\r\n\t\t})\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,OAAOC,kBAAkB,MAAM,yBAAyB;AAExDC,QAAQ,CAAC,oBAAoB,EAAE,YAAM;EACpCC,EAAE,CAAC,kEAAkE,EAAE,YAAM;IAC5E,OAAOF,kBAAkB,CAACD,IAAI,CAACI,OAAO,CAAC,0CAA0C,CAAC,CAAC,CAACC,IAAI,CAAC,UAACC,UAAU,EAAK;MACxGA,UAAU,CAACC,MAAM,CAACC,IAAI,CAACC,KAAK,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import readXlsxFile from './readXlsxFileWebWorker.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Reads the list of sheet names in an XLSX file in a Web Worker.
|
|
4
5
|
* @param {file} file - The file.
|
|
5
6
|
* @return {Promise} Resolves to an array of objects of shape `{ name: string }`.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
8
|
export default function readSheetNames(file) {
|
|
9
9
|
return readXlsxFile(file, {
|
|
10
10
|
getSheets: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSheetNamesWebWorker.js","names":["readXlsxFile","readSheetNames","file","getSheets","then","sheets","map","sheet","name"],"sources":["../../source/read/readSheetNamesWebWorker.js"],"sourcesContent":["import readXlsxFile from './readXlsxFileWebWorker.js'\r\n\r\n/**\r\n * Reads the list of sheet names in an XLSX file in a Web Worker.\r\n * @param {file} file - The file.\r\n * @return {Promise} Resolves to an array of objects of shape `{ name: string }`.\r\n */\r\nexport default function readSheetNames(file) {\r\n\treturn readXlsxFile(file, { getSheets: true })\r\n\t\t.then(sheets => sheets.map(sheet => sheet.name))\r\n}"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"readSheetNamesWebWorker.js","names":["readXlsxFile","readSheetNames","file","getSheets","then","sheets","map","sheet","name"],"sources":["../../source/read/readSheetNamesWebWorker.js"],"sourcesContent":["import readXlsxFile from './readXlsxFileWebWorker.js'\r\n\r\n/**\r\n * Reads the list of sheet names in an XLSX file in a Web Worker.\r\n * @param {file} file - The file.\r\n * @return {Promise} Resolves to an array of objects of shape `{ name: string }`.\r\n */\r\nexport default function readSheetNames(file) {\r\n\treturn readXlsxFile(file, { getSheets: true })\r\n\t\t.then(sheets => sheets.map(sheet => sheet.name))\r\n}"],"mappings":"AAAA,OAAOA,YAAY,MAAM,4BAA4B;;AAErD;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAcA,CAACC,IAAI,EAAE;EAC5C,OAAOF,YAAY,CAACE,IAAI,EAAE;IAAEC,SAAS,EAAE;EAAK,CAAC,CAAC,CAC5CC,IAAI,CAAC,UAAAC,MAAM;IAAA,OAAIA,MAAM,CAACC,GAAG,CAAC,UAAAC,KAAK;MAAA,OAAIA,KAAK,CAACC,IAAI;IAAA,EAAC;EAAA,EAAC;AAClD"}
|
package/modules/read/readXlsx.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
1
2
|
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
2
|
-
|
|
3
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
|
|
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
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
10
|
import parseProperties from './parseProperties.js';
|
|
14
11
|
import parseFilePaths from './parseFilePaths.js';
|
|
15
12
|
import parseStyles from './parseStyles.js';
|
|
16
13
|
import parseSharedStrings from './parseSharedStrings.js';
|
|
17
14
|
import parseSheet from './parseSheet.js';
|
|
18
|
-
import getData from './getData.js';
|
|
15
|
+
import getData from './getData.js';
|
|
16
|
+
|
|
17
|
+
// For an introduction in reading `*.xlsx` files see "The minimum viable XLSX reader":
|
|
19
18
|
// https://www.brendanlong.com/the-minimum-viable-xlsx-reader.html
|
|
20
19
|
|
|
21
20
|
/**
|
|
@@ -26,34 +25,33 @@ import getData from './getData.js'; // For an introduction in reading `*.xlsx` f
|
|
|
26
25
|
* @param {object} contents - A list of XML files inside XLSX file (which is a zipped directory).
|
|
27
26
|
* @return {object} An object of shape `{ data, cells, properties }`. `data: string[][]` is an array of rows, each row being an array of cell values. `cells: string[][]` is an array of rows, each row being an array of cells. `properties: object` is the spreadsheet properties (e.g. whether date epoch is 1904 instead of 1900).
|
|
28
27
|
*/
|
|
29
|
-
|
|
30
28
|
export default function readXlsx(contents, xml) {
|
|
31
29
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
32
|
-
|
|
33
30
|
if (!options.sheet) {
|
|
34
31
|
options = _objectSpread({
|
|
35
32
|
sheet: 1
|
|
36
33
|
}, options);
|
|
37
34
|
}
|
|
38
|
-
|
|
39
35
|
var getXmlFileContent = function getXmlFileContent(filePath) {
|
|
40
36
|
if (!contents[filePath]) {
|
|
41
37
|
throw new Error("\"".concat(filePath, "\" file not found inside the *.xlsx file zip archive"));
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
return contents[filePath];
|
|
45
|
-
};
|
|
46
|
-
// https://github.com/tidyverse/readxl/issues/104
|
|
47
|
-
|
|
40
|
+
};
|
|
48
41
|
|
|
49
|
-
|
|
42
|
+
// Some Excel editors don't want to use standard naming scheme for sheet files.
|
|
43
|
+
// https://github.com/tidyverse/readxl/issues/104
|
|
44
|
+
var filePaths = parseFilePaths(getXmlFileContent('xl/_rels/workbook.xml.rels'), xml);
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
// Default file path for "shared strings": "xl/sharedStrings.xml".
|
|
47
|
+
var values = filePaths.sharedStrings ? parseSharedStrings(getXmlFileContent(filePaths.sharedStrings), xml) : [];
|
|
52
48
|
|
|
49
|
+
// Default file path for "styles": "xl/styles.xml".
|
|
53
50
|
var styles = filePaths.styles ? parseStyles(getXmlFileContent(filePaths.styles), xml) : {};
|
|
54
|
-
var properties = parseProperties(getXmlFileContent('xl/workbook.xml'), xml);
|
|
55
|
-
// https://github.com/catamphetamine/read-excel-file/issues/14
|
|
51
|
+
var properties = parseProperties(getXmlFileContent('xl/workbook.xml'), xml);
|
|
56
52
|
|
|
53
|
+
// A feature for getting the list of sheets in an Excel file.
|
|
54
|
+
// https://github.com/catamphetamine/read-excel-file/issues/14
|
|
57
55
|
if (options.getSheets) {
|
|
58
56
|
return properties.sheets.map(function (_ref) {
|
|
59
57
|
var name = _ref.name;
|
|
@@ -61,47 +59,51 @@ export default function readXlsx(contents, xml) {
|
|
|
61
59
|
name: name
|
|
62
60
|
};
|
|
63
61
|
});
|
|
64
|
-
}
|
|
62
|
+
}
|
|
65
63
|
|
|
64
|
+
// Find the sheet by name, or take the first one.
|
|
65
|
+
var sheetId = getSheetId(options.sheet, properties.sheets);
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
// If the sheet wasn't found then throw an error.
|
|
68
68
|
// Example: "xl/worksheets/sheet1.xml".
|
|
69
|
-
|
|
70
69
|
if (!sheetId || !filePaths.sheets[sheetId]) {
|
|
71
70
|
throw createSheetNotFoundError(options.sheet, properties.sheets);
|
|
72
|
-
}
|
|
73
|
-
|
|
71
|
+
}
|
|
74
72
|
|
|
75
|
-
|
|
73
|
+
// Parse sheet data.
|
|
74
|
+
var sheet = parseSheet(getXmlFileContent(filePaths.sheets[sheetId]), xml, values, styles, properties, options);
|
|
75
|
+
options = _objectSpread({
|
|
76
|
+
// Create a `rowIndexMap` for the original dataset, if not passed,
|
|
77
|
+
// because "empty" rows will be dropped from the input data.
|
|
78
|
+
rowMap: []
|
|
79
|
+
}, options);
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
// Get spreadsheet data.
|
|
82
|
+
var data = getData(sheet, options);
|
|
78
83
|
|
|
84
|
+
// Can return properties, if required.
|
|
79
85
|
if (options.properties) {
|
|
80
86
|
return {
|
|
81
87
|
data: data,
|
|
82
88
|
properties: properties
|
|
83
89
|
};
|
|
84
|
-
}
|
|
85
|
-
|
|
90
|
+
}
|
|
86
91
|
|
|
92
|
+
// Return spreadsheet data.
|
|
87
93
|
return data;
|
|
88
94
|
}
|
|
89
|
-
|
|
90
95
|
function getSheetId(sheet, sheets) {
|
|
91
96
|
if (typeof sheet === 'number') {
|
|
92
97
|
var _sheet = sheets[sheet - 1];
|
|
93
98
|
return _sheet && _sheet.relationId;
|
|
94
99
|
}
|
|
95
|
-
|
|
96
100
|
for (var _iterator = _createForOfIteratorHelperLoose(sheets), _step; !(_step = _iterator()).done;) {
|
|
97
101
|
var _sheet2 = _step.value;
|
|
98
|
-
|
|
99
102
|
if (_sheet2.name === sheet) {
|
|
100
103
|
return _sheet2.relationId;
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
|
-
|
|
105
107
|
function createSheetNotFoundError(sheet, sheets) {
|
|
106
108
|
var sheetsList = sheets && sheets.map(function (sheet, i) {
|
|
107
109
|
return "\"".concat(sheet.name, "\" (#").concat(i + 1, ")");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readXlsx.js","names":["parseProperties","parseFilePaths","parseStyles","parseSharedStrings","parseSheet","getData","readXlsx","contents","xml","options","sheet","getXmlFileContent","filePath","Error","filePaths","values","sharedStrings","styles","properties","getSheets","sheets","map","name","sheetId","getSheetId","createSheetNotFoundError","data","_sheet","relationId","sheetsList","i","join"],"sources":["../../source/read/readXlsx.js"],"sourcesContent":["import parseProperties from './parseProperties.js'\r\nimport parseFilePaths from './parseFilePaths.js'\r\nimport parseStyles from './parseStyles.js'\r\nimport parseSharedStrings from './parseSharedStrings.js'\r\nimport parseSheet from './parseSheet.js'\r\nimport getData from './getData.js'\r\n\r\n// For an introduction in reading `*.xlsx` files see \"The minimum viable XLSX reader\":\r\n// https://www.brendanlong.com/the-minimum-viable-xlsx-reader.html\r\n\r\n/**\r\n * Reads an (unzipped) XLSX file structure into a 2D array of cells.\r\n * @param {object} contents - A list of XML files inside XLSX file (which is a zipped directory).\r\n * @param {number?} options.sheet - Workbook sheet id (`1` by default).\r\n * @param {string?} options.dateFormat - Date format, e.g. \"mm/dd/yyyy\". Values having this format template set will be parsed as dates.\r\n * @param {object} contents - A list of XML files inside XLSX file (which is a zipped directory).\r\n * @return {object} An object of shape `{ data, cells, properties }`. `data: string[][]` is an array of rows, each row being an array of cell values. `cells: string[][]` is an array of rows, each row being an array of cells. `properties: object` is the spreadsheet properties (e.g. whether date epoch is 1904 instead of 1900).\r\n */\r\nexport default function readXlsx(contents, xml, options = {}) {\r\n if (!options.sheet) {\r\n options = {\r\n sheet: 1,\r\n ...options\r\n }\r\n }\r\n\r\n const getXmlFileContent = (filePath) => {\r\n if (!contents[filePath]) {\r\n throw new Error(`\"${filePath}\" file not found inside the *.xlsx file zip archive`)\r\n }\r\n return contents[filePath]\r\n }\r\n\r\n // Some Excel editors don't want to use standard naming scheme for sheet files.\r\n // https://github.com/tidyverse/readxl/issues/104\r\n const filePaths = parseFilePaths(getXmlFileContent('xl/_rels/workbook.xml.rels'), xml)\r\n\r\n // Default file path for \"shared strings\": \"xl/sharedStrings.xml\".\r\n const values = filePaths.sharedStrings\r\n ? parseSharedStrings(getXmlFileContent(filePaths.sharedStrings), xml)\r\n : []\r\n\r\n // Default file path for \"styles\": \"xl/styles.xml\".\r\n const styles = filePaths.styles\r\n ? parseStyles(getXmlFileContent(filePaths.styles), xml)\r\n : {}\r\n\r\n const properties = parseProperties(getXmlFileContent('xl/workbook.xml'), xml)\r\n\r\n // A feature for getting the list of sheets in an Excel file.\r\n // https://github.com/catamphetamine/read-excel-file/issues/14\r\n if (options.getSheets) {\r\n return properties.sheets.map(({ name }) => ({\r\n name\r\n }))\r\n }\r\n\r\n // Find the sheet by name, or take the first one.\r\n const sheetId = getSheetId(options.sheet, properties.sheets)\r\n\r\n // If the sheet wasn't found then throw an error.\r\n // Example: \"xl/worksheets/sheet1.xml\".\r\n if (!sheetId || !filePaths.sheets[sheetId]) {\r\n throw createSheetNotFoundError(options.sheet, properties.sheets)\r\n }\r\n\r\n // Parse sheet data.\r\n const sheet = parseSheet(\r\n getXmlFileContent(filePaths.sheets[sheetId]),\r\n xml,\r\n values,\r\n styles,\r\n properties,\r\n options\r\n )\r\n\r\n // Get spreadsheet data.\r\n const data = getData(sheet, options)\r\n\r\n // Can return properties, if required.\r\n if (options.properties) {\r\n return {\r\n data,\r\n properties\r\n }\r\n }\r\n\r\n // Return spreadsheet data.\r\n return data\r\n}\r\n\r\nfunction getSheetId(sheet, sheets) {\r\n if (typeof sheet === 'number') {\r\n const _sheet = sheets[sheet - 1]\r\n return _sheet && _sheet.relationId\r\n }\r\n for (const _sheet of sheets) {\r\n if (_sheet.name === sheet) {\r\n return _sheet.relationId\r\n }\r\n }\r\n}\r\n\r\nfunction createSheetNotFoundError(sheet, sheets) {\r\n const sheetsList = sheets && sheets.map((sheet, i) => `\"${sheet.name}\" (#${i + 1})`).join(', ')\r\n return new Error(`Sheet ${typeof sheet === 'number' ? '#' + sheet : '\"' + sheet + '\"'} not found in the *.xlsx file.${sheets ? ' Available sheets: ' + sheetsList + '.' : ''}`)\r\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"readXlsx.js","names":["parseProperties","parseFilePaths","parseStyles","parseSharedStrings","parseSheet","getData","readXlsx","contents","xml","options","arguments","length","undefined","sheet","_objectSpread","getXmlFileContent","filePath","Error","concat","filePaths","values","sharedStrings","styles","properties","getSheets","sheets","map","_ref","name","sheetId","getSheetId","createSheetNotFoundError","rowMap","data","_sheet","relationId","_iterator","_createForOfIteratorHelperLoose","_step","done","value","sheetsList","i","join"],"sources":["../../source/read/readXlsx.js"],"sourcesContent":["import parseProperties from './parseProperties.js'\r\nimport parseFilePaths from './parseFilePaths.js'\r\nimport parseStyles from './parseStyles.js'\r\nimport parseSharedStrings from './parseSharedStrings.js'\r\nimport parseSheet from './parseSheet.js'\r\nimport getData from './getData.js'\r\n\r\n// For an introduction in reading `*.xlsx` files see \"The minimum viable XLSX reader\":\r\n// https://www.brendanlong.com/the-minimum-viable-xlsx-reader.html\r\n\r\n/**\r\n * Reads an (unzipped) XLSX file structure into a 2D array of cells.\r\n * @param {object} contents - A list of XML files inside XLSX file (which is a zipped directory).\r\n * @param {number?} options.sheet - Workbook sheet id (`1` by default).\r\n * @param {string?} options.dateFormat - Date format, e.g. \"mm/dd/yyyy\". Values having this format template set will be parsed as dates.\r\n * @param {object} contents - A list of XML files inside XLSX file (which is a zipped directory).\r\n * @return {object} An object of shape `{ data, cells, properties }`. `data: string[][]` is an array of rows, each row being an array of cell values. `cells: string[][]` is an array of rows, each row being an array of cells. `properties: object` is the spreadsheet properties (e.g. whether date epoch is 1904 instead of 1900).\r\n */\r\nexport default function readXlsx(contents, xml, options = {}) {\r\n if (!options.sheet) {\r\n options = {\r\n sheet: 1,\r\n ...options\r\n }\r\n }\r\n\r\n const getXmlFileContent = (filePath) => {\r\n if (!contents[filePath]) {\r\n throw new Error(`\"${filePath}\" file not found inside the *.xlsx file zip archive`)\r\n }\r\n return contents[filePath]\r\n }\r\n\r\n // Some Excel editors don't want to use standard naming scheme for sheet files.\r\n // https://github.com/tidyverse/readxl/issues/104\r\n const filePaths = parseFilePaths(getXmlFileContent('xl/_rels/workbook.xml.rels'), xml)\r\n\r\n // Default file path for \"shared strings\": \"xl/sharedStrings.xml\".\r\n const values = filePaths.sharedStrings\r\n ? parseSharedStrings(getXmlFileContent(filePaths.sharedStrings), xml)\r\n : []\r\n\r\n // Default file path for \"styles\": \"xl/styles.xml\".\r\n const styles = filePaths.styles\r\n ? parseStyles(getXmlFileContent(filePaths.styles), xml)\r\n : {}\r\n\r\n const properties = parseProperties(getXmlFileContent('xl/workbook.xml'), xml)\r\n\r\n // A feature for getting the list of sheets in an Excel file.\r\n // https://github.com/catamphetamine/read-excel-file/issues/14\r\n if (options.getSheets) {\r\n return properties.sheets.map(({ name }) => ({\r\n name\r\n }))\r\n }\r\n\r\n // Find the sheet by name, or take the first one.\r\n const sheetId = getSheetId(options.sheet, properties.sheets)\r\n\r\n // If the sheet wasn't found then throw an error.\r\n // Example: \"xl/worksheets/sheet1.xml\".\r\n if (!sheetId || !filePaths.sheets[sheetId]) {\r\n throw createSheetNotFoundError(options.sheet, properties.sheets)\r\n }\r\n\r\n // Parse sheet data.\r\n const sheet = parseSheet(\r\n getXmlFileContent(filePaths.sheets[sheetId]),\r\n xml,\r\n values,\r\n styles,\r\n properties,\r\n options\r\n )\r\n\r\n options = {\r\n // Create a `rowIndexMap` for the original dataset, if not passed,\r\n // because \"empty\" rows will be dropped from the input data.\r\n rowMap: [],\r\n ...options\r\n }\r\n\r\n // Get spreadsheet data.\r\n const data = getData(sheet, options)\r\n\r\n // Can return properties, if required.\r\n if (options.properties) {\r\n return {\r\n data,\r\n properties\r\n }\r\n }\r\n\r\n // Return spreadsheet data.\r\n return data\r\n}\r\n\r\nfunction getSheetId(sheet, sheets) {\r\n if (typeof sheet === 'number') {\r\n const _sheet = sheets[sheet - 1]\r\n return _sheet && _sheet.relationId\r\n }\r\n for (const _sheet of sheets) {\r\n if (_sheet.name === sheet) {\r\n return _sheet.relationId\r\n }\r\n }\r\n}\r\n\r\nfunction createSheetNotFoundError(sheet, sheets) {\r\n const sheetsList = sheets && sheets.map((sheet, i) => `\"${sheet.name}\" (#${i + 1})`).join(', ')\r\n return new Error(`Sheet ${typeof sheet === 'number' ? '#' + sheet : '\"' + sheet + '\"'} not found in the *.xlsx file.${sheets ? ' Available sheets: ' + sheetsList + '.' : ''}`)\r\n}"],"mappings":";;;;;;;;;AAAA,OAAOA,eAAe,MAAM,sBAAsB;AAClD,OAAOC,cAAc,MAAM,qBAAqB;AAChD,OAAOC,WAAW,MAAM,kBAAkB;AAC1C,OAAOC,kBAAkB,MAAM,yBAAyB;AACxD,OAAOC,UAAU,MAAM,iBAAiB;AACxC,OAAOC,OAAO,MAAM,cAAc;;AAElC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,QAAQA,CAACC,QAAQ,EAAEC,GAAG,EAAgB;EAAA,IAAdC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1D,IAAI,CAACD,OAAO,CAACI,KAAK,EAAE;IAClBJ,OAAO,GAAAK,aAAA;MACLD,KAAK,EAAE;IAAC,GACLJ,OAAO,CACX;EACH;EAEA,IAAMM,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAIC,QAAQ,EAAK;IACtC,IAAI,CAACT,QAAQ,CAACS,QAAQ,CAAC,EAAE;MACvB,MAAM,IAAIC,KAAK,MAAAC,MAAA,CAAKF,QAAQ,yDAAqD,CAAC;IACpF;IACA,OAAOT,QAAQ,CAACS,QAAQ,CAAC;EAC3B,CAAC;;EAED;EACA;EACA,IAAMG,SAAS,GAAGlB,cAAc,CAACc,iBAAiB,CAAC,4BAA4B,CAAC,EAAEP,GAAG,CAAC;;EAEtF;EACA,IAAMY,MAAM,GAAGD,SAAS,CAACE,aAAa,GAClClB,kBAAkB,CAACY,iBAAiB,CAACI,SAAS,CAACE,aAAa,CAAC,EAAEb,GAAG,CAAC,GACnE,EAAE;;EAEN;EACA,IAAMc,MAAM,GAAGH,SAAS,CAACG,MAAM,GAC3BpB,WAAW,CAACa,iBAAiB,CAACI,SAAS,CAACG,MAAM,CAAC,EAAEd,GAAG,CAAC,GACrD,CAAC,CAAC;EAEN,IAAMe,UAAU,GAAGvB,eAAe,CAACe,iBAAiB,CAAC,iBAAiB,CAAC,EAAEP,GAAG,CAAC;;EAE7E;EACA;EACA,IAAIC,OAAO,CAACe,SAAS,EAAE;IACrB,OAAOD,UAAU,CAACE,MAAM,CAACC,GAAG,CAAC,UAAAC,IAAA;MAAA,IAAGC,IAAI,GAAAD,IAAA,CAAJC,IAAI;MAAA,OAAQ;QAC1CA,IAAI,EAAJA;MACF,CAAC;IAAA,CAAC,CAAC;EACL;;EAEA;EACA,IAAMC,OAAO,GAAGC,UAAU,CAACrB,OAAO,CAACI,KAAK,EAAEU,UAAU,CAACE,MAAM,CAAC;;EAE5D;EACA;EACA,IAAI,CAACI,OAAO,IAAI,CAACV,SAAS,CAACM,MAAM,CAACI,OAAO,CAAC,EAAE;IAC1C,MAAME,wBAAwB,CAACtB,OAAO,CAACI,KAAK,EAAEU,UAAU,CAACE,MAAM,CAAC;EAClE;;EAEA;EACA,IAAMZ,KAAK,GAAGT,UAAU,CACtBW,iBAAiB,CAACI,SAAS,CAACM,MAAM,CAACI,OAAO,CAAC,CAAC,EAC5CrB,GAAG,EACHY,MAAM,EACNE,MAAM,EACNC,UAAU,EACVd,OACF,CAAC;EAEDA,OAAO,GAAAK,aAAA;IACL;IACA;IACAkB,MAAM,EAAE;EAAE,GACPvB,OAAO,CACX;;EAED;EACA,IAAMwB,IAAI,GAAG5B,OAAO,CAACQ,KAAK,EAAEJ,OAAO,CAAC;;EAEpC;EACA,IAAIA,OAAO,CAACc,UAAU,EAAE;IACtB,OAAO;MACLU,IAAI,EAAJA,IAAI;MACJV,UAAU,EAAVA;IACF,CAAC;EACH;;EAEA;EACA,OAAOU,IAAI;AACb;AAEA,SAASH,UAAUA,CAACjB,KAAK,EAAEY,MAAM,EAAE;EACjC,IAAI,OAAOZ,KAAK,KAAK,QAAQ,EAAE;IAC7B,IAAMqB,MAAM,GAAGT,MAAM,CAACZ,KAAK,GAAG,CAAC,CAAC;IAChC,OAAOqB,MAAM,IAAIA,MAAM,CAACC,UAAU;EACpC;EACA,SAAAC,SAAA,GAAAC,+BAAA,CAAqBZ,MAAM,GAAAa,KAAA,IAAAA,KAAA,GAAAF,SAAA,IAAAG,IAAA,GAAE;IAAA,IAAlBL,OAAM,GAAAI,KAAA,CAAAE,KAAA;IACf,IAAIN,OAAM,CAACN,IAAI,KAAKf,KAAK,EAAE;MACzB,OAAOqB,OAAM,CAACC,UAAU;IAC1B;EACF;AACF;AAEA,SAASJ,wBAAwBA,CAAClB,KAAK,EAAEY,MAAM,EAAE;EAC/C,IAAMgB,UAAU,GAAGhB,MAAM,IAAIA,MAAM,CAACC,GAAG,CAAC,UAACb,KAAK,EAAE6B,CAAC;IAAA,YAAAxB,MAAA,CAASL,KAAK,CAACe,IAAI,WAAAV,MAAA,CAAOwB,CAAC,GAAG,CAAC;EAAA,CAAG,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;EAC/F,OAAO,IAAI1B,KAAK,UAAAC,MAAA,CAAU,OAAOL,KAAK,KAAK,QAAQ,GAAG,GAAG,GAAGA,KAAK,GAAG,GAAG,GAAGA,KAAK,GAAG,GAAG,oCAAAK,MAAA,CAAiCO,MAAM,GAAG,qBAAqB,GAAGgB,UAAU,GAAG,GAAG,GAAG,EAAE,CAAE,CAAC;AACjL"}
|