@microsoft/connected-workbooks 3.3.2-beta → 3.4.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/dist/utils/constants.js +87 -49
- package/dist/utils/documentUtils.js +1 -1
- package/dist/utils/gridUtils.js +8 -8
- package/dist/utils/mashupDocumentParser.js +1 -1
- package/dist/utils/pqUtils.js +3 -3
- package/dist/utils/tableUtils.js +11 -4
- package/dist/utils/xmlInnerPartsUtils.js +245 -13
- package/dist/utils/xmlPartsUtils.js +74 -4
- package/dist/workbookManager.js +3 -3
- package/package.json +7 -3
- package/dist/src/generators.js +0 -15
- package/dist/src/types.js +0 -28
- package/dist/src/utils/arrayUtils.js +0 -51
- package/dist/src/utils/constants.js +0 -175
- package/dist/src/utils/documentUtils.js +0 -167
- package/dist/src/utils/gridUtils.js +0 -103
- package/dist/src/utils/htmlUtils.js +0 -19
- package/dist/src/utils/index.js +0 -24
- package/dist/src/utils/mashupDocumentParser.js +0 -188
- package/dist/src/utils/pqUtils.js +0 -194
- package/dist/src/utils/tableUtils.js +0 -233
- package/dist/src/utils/xmlInnerPartsUtils.js +0 -431
- package/dist/src/utils/xmlPartsUtils.js +0 -178
- package/dist/src/workbookTemplate.js +0 -9
- package/dist/tests/arrayUtils.test.js +0 -66
- package/dist/tests/documentUtils.test.js +0 -70
- package/dist/tests/gridUtils.test.js +0 -214
- package/dist/tests/htmlUtils.test.js +0 -111
- package/dist/tests/mashupDocumentParser.test.js +0 -113
- package/dist/tests/mocks/PqMock.js +0 -7
- package/dist/tests/mocks/index.js +0 -24
- package/dist/tests/mocks/section1mSimpleQueryMock.js +0 -8
- package/dist/tests/mocks/xmlMocks.js +0 -14
- package/dist/tests/tableUtils.test.js +0 -70
- package/dist/tests/workbookQueryTemplate.test.js +0 -218
- package/dist/tests/workbookTableTemplate.test.js +0 -126
- package/dist/tests/xmlInnerPartsUtils.test.js +0 -273
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT license.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.textResultType = exports.application = exports.uint8ArrayType = exports.blobFileType = exports.relationshipErr = exports.columnIndexOutOfRangeErr = exports.xlRelsNotFoundErr = exports.relsNotFoundErr = exports.arrayIsntMxNErr = exports.unexpectedErr = exports.promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr = exports.InvalidColumnNameErr = exports.stylesNotFoundErr = exports.EmptyQueryNameErr = exports.QueryNameInvalidCharsErr = exports.QueryNameMaxLengthErr = exports.invalidDataTypeErr = exports.headerNotFoundErr = exports.invalidValueInColumnErr = exports.tableReferenceNotFoundErr = exports.tableNotFoundErr = exports.queryTableNotFoundErr = exports.templateWithInitialDataErr = exports.formulaSectionNotFoundErr = exports.queryConnectionNotFoundErr = exports.queryAndPivotTableNotFoundErr = exports.queryNameNotFoundErr = exports.emptyQueryMashupErr = exports.base64NotFoundErr = exports.sheetsNotFoundErr = exports.WorkbookNotFoundERR = exports.connectionsNotFoundErr = exports.sharedStringsNotFoundErr = exports.docPropsAppXmlPath = exports.labelInfoXmlPath = exports.workbookRelsXmlPath = exports.docPropsRootElement = exports.docMetadataXmlPath = exports.relsXmlPath = exports.docPropsCoreXmlPath = exports.section1mPath = exports.pivotCachesPath = exports.tablesFolderPath = exports.queryTablesPath = exports.workbookXmlPath = exports.queryTableXmlPath = exports.tableXmlPath = exports.sheetsXmlPath = exports.sharedStringsXmlPath = exports.connectionsXmlPath = void 0;
|
|
6
|
-
exports.OFU = exports.headers = exports.URLS = exports.defaults = exports.elementAttributesValues = exports.dataTypeKind = exports.elementAttributes = exports.element = exports.BOM = exports.falseStr = exports.trueStr = exports.maxQueryLength = exports.divider = exports.section1PathPrefix = exports.emptyValue = exports.falseValue = exports.trueValue = exports.pivotCachesPathPrefix = exports.xmlTextResultType = void 0;
|
|
7
|
-
exports.connectionsXmlPath = "xl/connections.xml";
|
|
8
|
-
exports.sharedStringsXmlPath = "xl/sharedStrings.xml";
|
|
9
|
-
exports.sheetsXmlPath = "xl/worksheets/sheet1.xml";
|
|
10
|
-
exports.tableXmlPath = "xl/tables/table1.xml";
|
|
11
|
-
exports.queryTableXmlPath = "xl/queryTables/queryTable1.xml";
|
|
12
|
-
exports.workbookXmlPath = "xl/workbook.xml";
|
|
13
|
-
exports.queryTablesPath = "xl/queryTables/";
|
|
14
|
-
exports.tablesFolderPath = "xl/tables/";
|
|
15
|
-
exports.pivotCachesPath = "xl/pivotCache/";
|
|
16
|
-
exports.section1mPath = "Formulas/Section1.m";
|
|
17
|
-
exports.docPropsCoreXmlPath = "docProps/core.xml";
|
|
18
|
-
exports.relsXmlPath = "_rels/.rels";
|
|
19
|
-
exports.docMetadataXmlPath = "docMetadata";
|
|
20
|
-
exports.docPropsRootElement = "cp:coreProperties";
|
|
21
|
-
exports.workbookRelsXmlPath = "xl/_rels/workbook.xml.rels";
|
|
22
|
-
exports.labelInfoXmlPath = "docMetadata/LabelInfo.xml";
|
|
23
|
-
exports.docPropsAppXmlPath = "docProps/app.xml";
|
|
24
|
-
exports.sharedStringsNotFoundErr = "SharedStrings were not found in template";
|
|
25
|
-
exports.connectionsNotFoundErr = "Connections were not found in template";
|
|
26
|
-
exports.WorkbookNotFoundERR = "workbook was not found in template";
|
|
27
|
-
exports.sheetsNotFoundErr = "Sheets were not found in template";
|
|
28
|
-
exports.base64NotFoundErr = "Base64 was not found in template";
|
|
29
|
-
exports.emptyQueryMashupErr = "Query mashup is empty";
|
|
30
|
-
exports.queryNameNotFoundErr = "Query name was not found";
|
|
31
|
-
exports.queryAndPivotTableNotFoundErr = "No such query found in Query Table or Pivot Table found in given template";
|
|
32
|
-
exports.queryConnectionNotFoundErr = "No connection found for query";
|
|
33
|
-
exports.formulaSectionNotFoundErr = "Formula section wasn't found in template";
|
|
34
|
-
exports.templateWithInitialDataErr = "Cannot use a template file with initial data";
|
|
35
|
-
exports.queryTableNotFoundErr = "Query table wasn't found in template";
|
|
36
|
-
exports.tableNotFoundErr = "Table wasn't found in template";
|
|
37
|
-
exports.tableReferenceNotFoundErr = "Reference not found in the table XML.";
|
|
38
|
-
exports.invalidValueInColumnErr = "Invalid cell value in column";
|
|
39
|
-
exports.headerNotFoundErr = "Invalid JSON file, header is missing";
|
|
40
|
-
exports.invalidDataTypeErr = "Invalid JSON file, invalid data type";
|
|
41
|
-
exports.QueryNameMaxLengthErr = "Query names are limited to 80 characters";
|
|
42
|
-
exports.QueryNameInvalidCharsErr = 'Query names cannot contain periods or quotation marks. (. ")';
|
|
43
|
-
exports.EmptyQueryNameErr = "Query name cannot be empty";
|
|
44
|
-
exports.stylesNotFoundErr = "Styles were not found in template";
|
|
45
|
-
exports.InvalidColumnNameErr = "Invalid column name";
|
|
46
|
-
exports.promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr = "Headers cannot be promoted without adjusting column names";
|
|
47
|
-
exports.unexpectedErr = "Unexpected error";
|
|
48
|
-
exports.arrayIsntMxNErr = "Array isn't MxN";
|
|
49
|
-
exports.relsNotFoundErr = ".rels were not found in template";
|
|
50
|
-
exports.xlRelsNotFoundErr = "workbook.xml.rels were not found xl";
|
|
51
|
-
exports.columnIndexOutOfRangeErr = "Column index out of range";
|
|
52
|
-
exports.relationshipErr = "Relationship not found";
|
|
53
|
-
exports.blobFileType = "blob";
|
|
54
|
-
exports.uint8ArrayType = "uint8array";
|
|
55
|
-
exports.application = "application/xlsx";
|
|
56
|
-
exports.textResultType = "text";
|
|
57
|
-
exports.xmlTextResultType = "text/xml";
|
|
58
|
-
exports.pivotCachesPathPrefix = "pivotCacheDefinition";
|
|
59
|
-
exports.trueValue = "1";
|
|
60
|
-
exports.falseValue = "0";
|
|
61
|
-
exports.emptyValue = "";
|
|
62
|
-
exports.section1PathPrefix = "Section1/";
|
|
63
|
-
exports.divider = "/";
|
|
64
|
-
exports.maxQueryLength = 80;
|
|
65
|
-
exports.trueStr = "true";
|
|
66
|
-
exports.falseStr = "false";
|
|
67
|
-
exports.BOM = "\ufeff";
|
|
68
|
-
exports.element = {
|
|
69
|
-
sharedStringTable: "sst",
|
|
70
|
-
text: "t",
|
|
71
|
-
sharedStringItem: "si",
|
|
72
|
-
cellValue: "v",
|
|
73
|
-
databaseProperties: "dbPr",
|
|
74
|
-
queryTable: "queryTable",
|
|
75
|
-
cacheSource: "cacheSource",
|
|
76
|
-
item: "Item",
|
|
77
|
-
items: "Items",
|
|
78
|
-
itemPath: "ItemPath",
|
|
79
|
-
itemType: "ItemType",
|
|
80
|
-
itemLocation: "ItemLocation",
|
|
81
|
-
entry: "Entry",
|
|
82
|
-
stableEntries: "StableEntries",
|
|
83
|
-
tableColumns: "tableColumns",
|
|
84
|
-
tableColumn: "tableColumn",
|
|
85
|
-
table: "table",
|
|
86
|
-
autoFilter: "autoFilter",
|
|
87
|
-
definedName: "definedName",
|
|
88
|
-
queryTableFields: "queryTableFields",
|
|
89
|
-
queryTableField: "queryTableField",
|
|
90
|
-
queryTableRefresh: "queryTableRefresh",
|
|
91
|
-
sheetData: "sheetData",
|
|
92
|
-
row: "row",
|
|
93
|
-
dimension: "dimension",
|
|
94
|
-
selection: "selection",
|
|
95
|
-
kindCell: "c",
|
|
96
|
-
sheet: "sheet",
|
|
97
|
-
relationships: "Relationships",
|
|
98
|
-
relationship: "Relationship"
|
|
99
|
-
};
|
|
100
|
-
exports.elementAttributes = {
|
|
101
|
-
connection: "connection",
|
|
102
|
-
command: "command",
|
|
103
|
-
refreshOnLoad: "refreshOnLoad",
|
|
104
|
-
count: "count",
|
|
105
|
-
uniqueCount: "uniqueCount",
|
|
106
|
-
queryTable: "queryTable",
|
|
107
|
-
connectionId: "connectionId",
|
|
108
|
-
cacheSource: "cacheSource",
|
|
109
|
-
name: "name",
|
|
110
|
-
description: "description",
|
|
111
|
-
id: "id",
|
|
112
|
-
Id: "Id",
|
|
113
|
-
relationId: "r:id",
|
|
114
|
-
relationId1: "RId1",
|
|
115
|
-
relationId2: "RId2",
|
|
116
|
-
relationId3: "RId3",
|
|
117
|
-
type: "Type",
|
|
118
|
-
value: "Value",
|
|
119
|
-
relationshipInfo: "RelationshipInfoContainer",
|
|
120
|
-
resultType: "ResultType",
|
|
121
|
-
fillColumnNames: "FillColumnNames",
|
|
122
|
-
fillTarget: "FillTarget",
|
|
123
|
-
fillLastUpdated: "FillLastUpdated",
|
|
124
|
-
day: "d",
|
|
125
|
-
uniqueName: "uniqueName",
|
|
126
|
-
queryTableFieldId: "queryTableFieldId",
|
|
127
|
-
reference: "ref",
|
|
128
|
-
sqref: "sqref",
|
|
129
|
-
tableColumnId: "tableColumnId",
|
|
130
|
-
nextId: "nextId",
|
|
131
|
-
row: "r",
|
|
132
|
-
spans: "spans",
|
|
133
|
-
x14acDyDescent: "x14ac:dyDescent",
|
|
134
|
-
xr3uid: "xr3:uid",
|
|
135
|
-
space: "xml:space",
|
|
136
|
-
target: "Target",
|
|
137
|
-
};
|
|
138
|
-
exports.dataTypeKind = {
|
|
139
|
-
string: "str",
|
|
140
|
-
number: "1",
|
|
141
|
-
boolean: "b",
|
|
142
|
-
};
|
|
143
|
-
exports.elementAttributesValues = {
|
|
144
|
-
connectionName: function (queryName) { return "Query - ".concat(queryName); },
|
|
145
|
-
connectionDescription: function (queryName) { return "Connection to the '".concat(queryName, "' query in the workbook."); },
|
|
146
|
-
connection: function (queryName) { return "Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=\"".concat(queryName, "\";"); },
|
|
147
|
-
connectionCommand: function (queryName) { return "SELECT * FROM [".concat(queryName, "]"); },
|
|
148
|
-
tableResultType: function () { return "sTable"; },
|
|
149
|
-
};
|
|
150
|
-
exports.defaults = {
|
|
151
|
-
queryName: "Query1",
|
|
152
|
-
sheetName: "Sheet1",
|
|
153
|
-
columnName: "Column",
|
|
154
|
-
tableName: "Table1",
|
|
155
|
-
};
|
|
156
|
-
exports.URLS = {
|
|
157
|
-
PQ: [
|
|
158
|
-
"http://schemas.microsoft.com/DataMashup",
|
|
159
|
-
"http://schemas.microsoft.com/DataExplorer",
|
|
160
|
-
"http://schemas.microsoft.com/DataMashup/Temp",
|
|
161
|
-
"http://schemas.microsoft.com/DataExplorer/Temp",
|
|
162
|
-
],
|
|
163
|
-
CONNECTED_WORKBOOK: "http://schemas.microsoft.com/ConnectedWorkbook",
|
|
164
|
-
};
|
|
165
|
-
// Content-Type header to indicate that the content is an Excel document
|
|
166
|
-
exports.headers = {
|
|
167
|
-
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
168
|
-
};
|
|
169
|
-
exports.OFU = {
|
|
170
|
-
ViewUrl: "https://view.officeapps.live.com/op/view.aspx?src=http://connectedWorkbooks.excel/",
|
|
171
|
-
PostUrl: "https://view.officeapps.live.com/op/viewpost.aspx?src=http://connectedWorkbooks.excel/",
|
|
172
|
-
AllowTyping: "AllowTyping",
|
|
173
|
-
WdOrigin: "wdOrigin",
|
|
174
|
-
OpenInExcelOririgin: "OpenInExcel",
|
|
175
|
-
};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT license.
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
-
function step(op) {
|
|
18
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
-
switch (op[0]) {
|
|
23
|
-
case 0: case 1: t = op; break;
|
|
24
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
-
default:
|
|
28
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
-
if (t[2]) _.ops.pop();
|
|
33
|
-
_.trys.pop(); continue;
|
|
34
|
-
}
|
|
35
|
-
op = body.call(thisArg, _);
|
|
36
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
var constants_1 = require("./constants");
|
|
42
|
-
var types_1 = require("../types");
|
|
43
|
-
var xmldom_qsa_1 = require("xmldom-qsa");
|
|
44
|
-
var createOrUpdateProperty = function (doc, parent, property, value) {
|
|
45
|
-
if (value === undefined) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
var elements = parent.getElementsByTagName(property);
|
|
49
|
-
if ((elements === null || elements === void 0 ? void 0 : elements.length) === 0) {
|
|
50
|
-
var newElement = doc.createElement(property);
|
|
51
|
-
newElement.textContent = value;
|
|
52
|
-
parent.appendChild(newElement);
|
|
53
|
-
}
|
|
54
|
-
else if (elements.length > 1) {
|
|
55
|
-
throw new Error("Invalid DocProps core.xml, multiple ".concat(property, " elements"));
|
|
56
|
-
}
|
|
57
|
-
else if ((elements === null || elements === void 0 ? void 0 : elements.length) > 0) {
|
|
58
|
-
elements[0].textContent = value;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var getDocPropsProperties = function (zip) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
-
var docPropsCoreXmlString, parser, doc, properties;
|
|
63
|
-
var _a;
|
|
64
|
-
return __generator(this, function (_b) {
|
|
65
|
-
switch (_b.label) {
|
|
66
|
-
case 0: return [4 /*yield*/, ((_a = zip.file(constants_1.docPropsCoreXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))];
|
|
67
|
-
case 1:
|
|
68
|
-
docPropsCoreXmlString = _b.sent();
|
|
69
|
-
if (docPropsCoreXmlString === undefined) {
|
|
70
|
-
throw new Error("DocProps core.xml was not found in template");
|
|
71
|
-
}
|
|
72
|
-
parser = new xmldom_qsa_1.DOMParser();
|
|
73
|
-
doc = parser.parseFromString(docPropsCoreXmlString, constants_1.xmlTextResultType);
|
|
74
|
-
properties = doc.getElementsByTagName(constants_1.docPropsRootElement).item(0);
|
|
75
|
-
if (properties === null) {
|
|
76
|
-
throw new Error("Invalid DocProps core.xml");
|
|
77
|
-
}
|
|
78
|
-
return [2 /*return*/, { doc: doc, properties: properties }];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}); };
|
|
82
|
-
var getCellReferenceAbsolute = function (col, row) {
|
|
83
|
-
return "$" + convertToExcelColumn(col) + "$" + row.toString();
|
|
84
|
-
};
|
|
85
|
-
var getCellReferenceRelative = function (col, row) {
|
|
86
|
-
return convertToExcelColumn(col) + row.toString();
|
|
87
|
-
};
|
|
88
|
-
var convertToExcelColumn = function (index) {
|
|
89
|
-
if (index >= 16384) {
|
|
90
|
-
throw new Error(constants_1.columnIndexOutOfRangeErr);
|
|
91
|
-
}
|
|
92
|
-
var columnStr = "";
|
|
93
|
-
var base = 26; // number of letters in the alphabet
|
|
94
|
-
while (index >= 0) {
|
|
95
|
-
var remainder = index % base;
|
|
96
|
-
columnStr = String.fromCharCode(remainder + 'A'.charCodeAt(0)) + columnStr;
|
|
97
|
-
index = Math.floor(index / base) - 1;
|
|
98
|
-
}
|
|
99
|
-
return columnStr;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Parse an Excel range (e.g. "B2:D10") and return its starting row and column indices.
|
|
103
|
-
* @param cellRangeRef - Range reference string.
|
|
104
|
-
* @returns Object with numeric row and column.
|
|
105
|
-
*/
|
|
106
|
-
var GetStartPosition = function (cellRangeRef) {
|
|
107
|
-
var match = cellRangeRef.toUpperCase().match(/^([A-Z]+)(\d+)/);
|
|
108
|
-
if (!match) {
|
|
109
|
-
return { row: 0, column: 0 };
|
|
110
|
-
}
|
|
111
|
-
var colLetters = match[1], rowStr = match[2];
|
|
112
|
-
var row = parseInt(rowStr, 10);
|
|
113
|
-
var column = colLetters
|
|
114
|
-
.split("")
|
|
115
|
-
.reduce(function (acc, char) { return acc * 26 + (char.charCodeAt(0) - "A".charCodeAt(0) + 1); }, 0);
|
|
116
|
-
return { row: row, column: column };
|
|
117
|
-
};
|
|
118
|
-
var createCellElement = function (doc, colIndex, rowIndex, data) {
|
|
119
|
-
var cell = doc.createElementNS(doc.documentElement.namespaceURI, constants_1.element.kindCell);
|
|
120
|
-
cell.setAttribute(constants_1.elementAttributes.row, getCellReferenceRelative(colIndex, rowIndex + 1));
|
|
121
|
-
var cellData = doc.createElementNS(doc.documentElement.namespaceURI, constants_1.element.cellValue);
|
|
122
|
-
updateCellData(data, cell, cellData, rowIndex === 0);
|
|
123
|
-
cell.appendChild(cellData);
|
|
124
|
-
return cell;
|
|
125
|
-
};
|
|
126
|
-
var updateCellData = function (data, cell, cellData, rowHeader) {
|
|
127
|
-
switch (resolveType(data, rowHeader)) {
|
|
128
|
-
case types_1.DataTypes.string:
|
|
129
|
-
cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.string);
|
|
130
|
-
break;
|
|
131
|
-
case types_1.DataTypes.number:
|
|
132
|
-
cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.number);
|
|
133
|
-
break;
|
|
134
|
-
case types_1.DataTypes.boolean:
|
|
135
|
-
cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.boolean);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
if (data.startsWith(" ") || data.endsWith(" ")) {
|
|
139
|
-
cellData.setAttribute(constants_1.elementAttributes.space, "preserve");
|
|
140
|
-
}
|
|
141
|
-
cellData.textContent = data;
|
|
142
|
-
};
|
|
143
|
-
var resolveType = function (originalData, rowHeader) {
|
|
144
|
-
var data = originalData;
|
|
145
|
-
if (rowHeader || data.trim() === "") {
|
|
146
|
-
// Headers and whitespace should be string by default.
|
|
147
|
-
return types_1.DataTypes.string;
|
|
148
|
-
}
|
|
149
|
-
var dataType = isNaN(Number(data)) ? types_1.DataTypes.string : types_1.DataTypes.number;
|
|
150
|
-
if (dataType == types_1.DataTypes.string) {
|
|
151
|
-
if (data.trim() == constants_1.trueStr || data.trim() == constants_1.falseStr) {
|
|
152
|
-
dataType = types_1.DataTypes.boolean;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return dataType;
|
|
156
|
-
};
|
|
157
|
-
exports.default = {
|
|
158
|
-
createOrUpdateProperty: createOrUpdateProperty,
|
|
159
|
-
getDocPropsProperties: getDocPropsProperties,
|
|
160
|
-
getCellReferenceRelative: getCellReferenceRelative,
|
|
161
|
-
getCellReferenceAbsolute: getCellReferenceAbsolute,
|
|
162
|
-
createCell: createCellElement,
|
|
163
|
-
updateCellData: updateCellData,
|
|
164
|
-
resolveType: resolveType,
|
|
165
|
-
convertToExcelColumn: convertToExcelColumn,
|
|
166
|
-
GetStartPosition: GetStartPosition,
|
|
167
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT license.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
var constants_1 = require("../utils/constants");
|
|
6
|
-
var parseToTableData = function (grid) {
|
|
7
|
-
var _a, _b, _c, _d;
|
|
8
|
-
if (grid === null || grid === undefined) {
|
|
9
|
-
grid = { data: [] };
|
|
10
|
-
}
|
|
11
|
-
if (grid.data === null || grid.data === undefined) {
|
|
12
|
-
grid.data = [];
|
|
13
|
-
}
|
|
14
|
-
var mergedGrid = {
|
|
15
|
-
config: {
|
|
16
|
-
promoteHeaders: (_b = (_a = grid.config) === null || _a === void 0 ? void 0 : _a.promoteHeaders) !== null && _b !== void 0 ? _b : false,
|
|
17
|
-
adjustColumnNames: (_d = (_c = grid.config) === null || _c === void 0 ? void 0 : _c.adjustColumnNames) !== null && _d !== void 0 ? _d : true,
|
|
18
|
-
},
|
|
19
|
-
data: grid.data.map(function (row) { return row.map(function (value) { var _a; return (_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : ""; }); }),
|
|
20
|
-
};
|
|
21
|
-
correctGrid(mergedGrid);
|
|
22
|
-
validateGrid(mergedGrid);
|
|
23
|
-
var columnNames = [];
|
|
24
|
-
if (mergedGrid.config.promoteHeaders && mergedGrid.config.adjustColumnNames) {
|
|
25
|
-
columnNames = getAdjustedColumnNames(mergedGrid.data.shift());
|
|
26
|
-
}
|
|
27
|
-
else if (mergedGrid.config.promoteHeaders && !mergedGrid.config.adjustColumnNames) {
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
29
|
-
columnNames = mergedGrid.data.shift();
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
columnNames = Array.from({ length: mergedGrid.data[0].length }, function (_, index) { return "".concat(constants_1.defaults.columnName, " ").concat(index + 1); });
|
|
33
|
-
}
|
|
34
|
-
return { columnNames: columnNames, rows: mergedGrid.data };
|
|
35
|
-
};
|
|
36
|
-
var correctGrid = function (grid) {
|
|
37
|
-
if (grid.data.length === 0) {
|
|
38
|
-
// empty grid fix
|
|
39
|
-
grid.config.promoteHeaders = false;
|
|
40
|
-
grid.data.push([""]);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
var getEmptyArray = function (n) { return Array.from({ length: n }, function () { return ""; }); };
|
|
44
|
-
if (grid.data[0].length === 0) {
|
|
45
|
-
grid.data[0] = [""];
|
|
46
|
-
}
|
|
47
|
-
// replace empty rows
|
|
48
|
-
grid.data.forEach(function (row, index) {
|
|
49
|
-
if (row.length === 0) {
|
|
50
|
-
grid.data[index] = getEmptyArray(grid.data[0].length);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (grid.config.promoteHeaders && grid.data.length === 1) {
|
|
54
|
-
// table in Excel should have at least 2 rows
|
|
55
|
-
grid.data.push(getEmptyArray(grid.data[0].length));
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
/*
|
|
59
|
-
* Validates the grid, throws an error if the grid is invalid.
|
|
60
|
-
* A valid grid has:
|
|
61
|
-
* - MxN structure.
|
|
62
|
-
* - If promoteHeaders is true - has at least 1 row, and in case adjustColumnNames is false, first row is unique and non empty.
|
|
63
|
-
*/
|
|
64
|
-
var validateGrid = function (grid) {
|
|
65
|
-
validateDataArrayDimensions(grid.data);
|
|
66
|
-
if (grid.config.promoteHeaders && grid.config.adjustColumnNames === false && !validateUniqueAndValidDataArray(grid.data[0])) {
|
|
67
|
-
throw new Error(constants_1.promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var validateDataArrayDimensions = function (arr) {
|
|
71
|
-
if (arr.length === 0 || arr[0].length === 0) {
|
|
72
|
-
throw new Error(constants_1.unexpectedErr);
|
|
73
|
-
}
|
|
74
|
-
if (!arr.every(function (innerArr) { return innerArr.length === arr[0].length; })) {
|
|
75
|
-
throw new Error(constants_1.arrayIsntMxNErr);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var validateUniqueAndValidDataArray = function (arr) {
|
|
79
|
-
if (arr.some(function (element) { return element === ""; })) {
|
|
80
|
-
return false; // Array contains empty elements
|
|
81
|
-
}
|
|
82
|
-
var uniqueSet = new Set(arr);
|
|
83
|
-
return uniqueSet.size === arr.length;
|
|
84
|
-
};
|
|
85
|
-
var getAdjustedColumnNames = function (columnNames) {
|
|
86
|
-
if (columnNames === undefined) {
|
|
87
|
-
throw new Error(constants_1.unexpectedErr);
|
|
88
|
-
}
|
|
89
|
-
var i = 1;
|
|
90
|
-
// replace empty column names with default names, can still conflict if columns exist, but we handle that later
|
|
91
|
-
columnNames = columnNames.map(function (columnName) { return columnName || "".concat(constants_1.defaults.columnName, " ").concat(i++); });
|
|
92
|
-
var uniqueNames = new Set();
|
|
93
|
-
return columnNames.map(function (name) {
|
|
94
|
-
var uniqueName = name;
|
|
95
|
-
i = 1;
|
|
96
|
-
while (uniqueNames.has(uniqueName)) {
|
|
97
|
-
uniqueName = "".concat(name, " (").concat(i++, ")");
|
|
98
|
-
}
|
|
99
|
-
uniqueNames.add(uniqueName);
|
|
100
|
-
return uniqueName;
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
exports.default = { parseToTableData: parseToTableData };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT license.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
var extractTableValues = function (table) {
|
|
6
|
-
var rows = [];
|
|
7
|
-
// Extract values from each row
|
|
8
|
-
for (var i = 0; i < table.rows.length; i++) {
|
|
9
|
-
var row = table.rows[i];
|
|
10
|
-
var rowData = [];
|
|
11
|
-
for (var j = 0; j < row.cells.length; j++) {
|
|
12
|
-
var cell = row.cells[j];
|
|
13
|
-
rowData.push(cell.textContent || "");
|
|
14
|
-
}
|
|
15
|
-
rows.push(rowData);
|
|
16
|
-
}
|
|
17
|
-
return rows;
|
|
18
|
-
};
|
|
19
|
-
exports.default = { extractTableValues: extractTableValues };
|
package/dist/src/utils/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT license.
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.gridUtils = exports.htmlUtils = exports.tableUtils = exports.xmlInnerPartsUtils = exports.xmlPartsUtils = exports.documentUtils = exports.arrayUtils = exports.pqUtils = void 0;
|
|
9
|
-
var pqUtils_1 = require("./pqUtils");
|
|
10
|
-
Object.defineProperty(exports, "pqUtils", { enumerable: true, get: function () { return __importDefault(pqUtils_1).default; } });
|
|
11
|
-
var arrayUtils_1 = require("./arrayUtils");
|
|
12
|
-
Object.defineProperty(exports, "arrayUtils", { enumerable: true, get: function () { return __importDefault(arrayUtils_1).default; } });
|
|
13
|
-
var documentUtils_1 = require("./documentUtils");
|
|
14
|
-
Object.defineProperty(exports, "documentUtils", { enumerable: true, get: function () { return __importDefault(documentUtils_1).default; } });
|
|
15
|
-
var xmlPartsUtils_1 = require("./xmlPartsUtils");
|
|
16
|
-
Object.defineProperty(exports, "xmlPartsUtils", { enumerable: true, get: function () { return __importDefault(xmlPartsUtils_1).default; } });
|
|
17
|
-
var xmlInnerPartsUtils_1 = require("./xmlInnerPartsUtils");
|
|
18
|
-
Object.defineProperty(exports, "xmlInnerPartsUtils", { enumerable: true, get: function () { return __importDefault(xmlInnerPartsUtils_1).default; } });
|
|
19
|
-
var tableUtils_1 = require("./tableUtils");
|
|
20
|
-
Object.defineProperty(exports, "tableUtils", { enumerable: true, get: function () { return __importDefault(tableUtils_1).default; } });
|
|
21
|
-
var htmlUtils_1 = require("./htmlUtils");
|
|
22
|
-
Object.defineProperty(exports, "htmlUtils", { enumerable: true, get: function () { return __importDefault(htmlUtils_1).default; } });
|
|
23
|
-
var gridUtils_1 = require("./gridUtils");
|
|
24
|
-
Object.defineProperty(exports, "gridUtils", { enumerable: true, get: function () { return __importDefault(gridUtils_1).default; } });
|