ooxml.js 2.5.2 → 2.6.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/README.md +1 -1
- package/dist/index.cjs +22 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/typed/docx/numbering.cjs +86 -0
- package/dist/typed/docx/numbering.d.cts +23 -0
- package/dist/typed/docx/numbering.d.ts +23 -0
- package/dist/typed/docx/numbering.js +83 -0
- package/dist/typed/docx/read.cjs +115 -15
- package/dist/typed/docx/read.d.cts +8 -0
- package/dist/typed/docx/read.d.ts +8 -0
- package/dist/typed/docx/read.js +117 -17
- package/dist/typed/docx/styles.cjs +26 -2
- package/dist/typed/docx/styles.js +26 -2
- package/dist/typed/pptx/read.cjs +5 -20
- package/dist/typed/pptx/read.js +5 -20
- package/dist/typed/shared/drawingml.cjs +112 -5
- package/dist/typed/shared/drawingml.d.cts +19 -2
- package/dist/typed/shared/drawingml.d.ts +19 -2
- package/dist/typed/shared/drawingml.js +111 -6
- package/dist/typed/shared/units.cjs +10 -0
- package/dist/typed/shared/units.d.cts +4 -1
- package/dist/typed/shared/units.d.ts +4 -1
- package/dist/typed/shared/units.js +8 -1
- package/dist/typed/xlsx/build.cjs +83 -55
- package/dist/typed/xlsx/build.js +83 -55
- package/dist/typed/xlsx/content.cjs +85 -15
- package/dist/typed/xlsx/content.js +85 -15
- package/dist/typed/xlsx/number-format.cjs +324 -0
- package/dist/typed/xlsx/number-format.d.cts +52 -0
- package/dist/typed/xlsx/number-format.d.ts +52 -0
- package/dist/typed/xlsx/number-format.js +312 -0
- package/dist/typed/xlsx/serial.cjs +109 -0
- package/dist/typed/xlsx/serial.d.cts +11 -0
- package/dist/typed/xlsx/serial.d.ts +11 -0
- package/dist/typed/xlsx/serial.js +102 -0
- package/dist/typed/xlsx/styles.cjs +73 -0
- package/dist/typed/xlsx/styles.d.cts +21 -0
- package/dist/typed/xlsx/styles.d.ts +21 -0
- package/dist/typed/xlsx/styles.js +69 -0
- package/package.json +1 -1
|
@@ -163,18 +163,123 @@ function readGroupXfrm(xfrm) {
|
|
|
163
163
|
childOffXPt: emuToPt(Number(cx)),
|
|
164
164
|
childOffYPt: emuToPt(Number(cy)),
|
|
165
165
|
childExtWidthPt: emuToPt(Number(ccx)),
|
|
166
|
-
childExtHeightPt: emuToPt(Number(ccy))
|
|
166
|
+
childExtHeightPt: emuToPt(Number(ccy)),
|
|
167
|
+
rotationDeg: base.rotationDeg,
|
|
168
|
+
flipH: base.flipH,
|
|
169
|
+
flipV: base.flipV
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function normalizeDeg(deg) {
|
|
173
|
+
const mod = deg % 360;
|
|
174
|
+
return mod < 0 ? mod + 360 : mod;
|
|
175
|
+
}
|
|
176
|
+
function canonicalizeGroupRotation(rotationDeg, flipH, flipV) {
|
|
177
|
+
if (flipH && flipV) return {
|
|
178
|
+
angleDeg: rotationDeg + 180,
|
|
179
|
+
mirrored: false
|
|
180
|
+
};
|
|
181
|
+
if (flipV) return {
|
|
182
|
+
angleDeg: rotationDeg + 180,
|
|
183
|
+
mirrored: true
|
|
184
|
+
};
|
|
185
|
+
if (flipH) return {
|
|
186
|
+
angleDeg: rotationDeg,
|
|
187
|
+
mirrored: true
|
|
188
|
+
};
|
|
189
|
+
return {
|
|
190
|
+
angleDeg: rotationDeg,
|
|
191
|
+
mirrored: false
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function composeRotation(outer, inner) {
|
|
195
|
+
if (!outer.mirrored) return {
|
|
196
|
+
angleDeg: normalizeDeg(outer.angleDeg + inner.angleDeg),
|
|
197
|
+
mirrored: inner.mirrored
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
angleDeg: normalizeDeg(outer.angleDeg - inner.angleDeg),
|
|
201
|
+
mirrored: !inner.mirrored
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function composeGroupTransform(own, parent) {
|
|
205
|
+
if (own === void 0) return;
|
|
206
|
+
const ownRotation = canonicalizeGroupRotation(own.rotationDeg, own.flipH, own.flipV);
|
|
207
|
+
if (parent === void 0) return {
|
|
208
|
+
offXPt: own.offXPt,
|
|
209
|
+
offYPt: own.offYPt,
|
|
210
|
+
extWidthPt: own.extWidthPt,
|
|
211
|
+
extHeightPt: own.extHeightPt,
|
|
212
|
+
childOffXPt: own.childOffXPt,
|
|
213
|
+
childOffYPt: own.childOffYPt,
|
|
214
|
+
childExtWidthPt: own.childExtWidthPt,
|
|
215
|
+
childExtHeightPt: own.childExtHeightPt,
|
|
216
|
+
compositeRotationDeg: normalizeDeg(ownRotation.angleDeg),
|
|
217
|
+
compositeMirrored: ownRotation.mirrored
|
|
218
|
+
};
|
|
219
|
+
const mapped = applyGroupTransform(parent, {
|
|
220
|
+
xPt: own.offXPt,
|
|
221
|
+
yPt: own.offYPt,
|
|
222
|
+
widthPt: own.extWidthPt,
|
|
223
|
+
heightPt: own.extHeightPt
|
|
224
|
+
});
|
|
225
|
+
const composite = composeRotation({
|
|
226
|
+
angleDeg: parent.compositeRotationDeg,
|
|
227
|
+
mirrored: parent.compositeMirrored
|
|
228
|
+
}, ownRotation);
|
|
229
|
+
return {
|
|
230
|
+
offXPt: mapped.xPt,
|
|
231
|
+
offYPt: mapped.yPt,
|
|
232
|
+
extWidthPt: mapped.widthPt,
|
|
233
|
+
extHeightPt: mapped.heightPt,
|
|
234
|
+
childOffXPt: own.childOffXPt,
|
|
235
|
+
childOffYPt: own.childOffYPt,
|
|
236
|
+
childExtWidthPt: own.childExtWidthPt,
|
|
237
|
+
childExtHeightPt: own.childExtHeightPt,
|
|
238
|
+
compositeRotationDeg: composite.angleDeg,
|
|
239
|
+
compositeMirrored: composite.mirrored
|
|
167
240
|
};
|
|
168
241
|
}
|
|
169
242
|
function applyGroupTransform(group, childFrame) {
|
|
170
243
|
const scaleX = group.childExtWidthPt === 0 ? 1 : group.extWidthPt / group.childExtWidthPt;
|
|
171
244
|
const scaleY = group.childExtHeightPt === 0 ? 1 : group.extHeightPt / group.childExtHeightPt;
|
|
245
|
+
const widthPt = childFrame.widthPt * scaleX;
|
|
246
|
+
const heightPt = childFrame.heightPt * scaleY;
|
|
247
|
+
const canonicalX = group.offXPt + (childFrame.xPt - group.childOffXPt) * scaleX;
|
|
248
|
+
const canonicalY = group.offYPt + (childFrame.yPt - group.childOffYPt) * scaleY;
|
|
249
|
+
if (group.compositeRotationDeg === 0 && !group.compositeMirrored) return {
|
|
250
|
+
xPt: canonicalX,
|
|
251
|
+
yPt: canonicalY,
|
|
252
|
+
widthPt,
|
|
253
|
+
heightPt
|
|
254
|
+
};
|
|
255
|
+
const groupCenterX = group.offXPt + group.extWidthPt / 2;
|
|
256
|
+
const groupCenterY = group.offYPt + group.extHeightPt / 2;
|
|
257
|
+
const boxCenterX = canonicalX + widthPt / 2;
|
|
258
|
+
const boxCenterY = canonicalY + heightPt / 2;
|
|
259
|
+
let dx = boxCenterX - groupCenterX;
|
|
260
|
+
const dy = boxCenterY - groupCenterY;
|
|
261
|
+
if (group.compositeMirrored) dx = -dx;
|
|
262
|
+
const rad = group.compositeRotationDeg * Math.PI / 180;
|
|
263
|
+
const cos = Math.cos(rad);
|
|
264
|
+
const sin = Math.sin(rad);
|
|
265
|
+
const rotatedX = dx * cos - dy * sin;
|
|
266
|
+
const rotatedY = dx * sin + dy * cos;
|
|
172
267
|
return {
|
|
173
|
-
xPt:
|
|
174
|
-
yPt:
|
|
175
|
-
widthPt
|
|
176
|
-
heightPt
|
|
268
|
+
xPt: groupCenterX + rotatedX - widthPt / 2,
|
|
269
|
+
yPt: groupCenterY + rotatedY - heightPt / 2,
|
|
270
|
+
widthPt,
|
|
271
|
+
heightPt
|
|
177
272
|
};
|
|
178
273
|
}
|
|
274
|
+
function composeShapeRotationDeg(parentTransform, ownRotationDeg) {
|
|
275
|
+
if (parentTransform === void 0) return normalizeDeg(ownRotationDeg);
|
|
276
|
+
return composeRotation({
|
|
277
|
+
angleDeg: parentTransform.compositeRotationDeg,
|
|
278
|
+
mirrored: parentTransform.compositeMirrored
|
|
279
|
+
}, {
|
|
280
|
+
angleDeg: ownRotationDeg,
|
|
281
|
+
mirrored: false
|
|
282
|
+
}).angleDeg;
|
|
283
|
+
}
|
|
179
284
|
//#endregion
|
|
180
|
-
export { EMPTY_THEME, applyGroupTransform, readColorMap, readGroupXfrm, readSchemeColor, readSolidFillColor, readSrgbColor, readTheme, readXfrm, resolveSchemeColorSlot, resolveThemeFontReference };
|
|
285
|
+
export { EMPTY_THEME, applyGroupTransform, composeGroupTransform, composeShapeRotationDeg, readColorMap, readGroupXfrm, readSchemeColor, readSolidFillColor, readSrgbColor, readTheme, readXfrm, resolveSchemeColorSlot, resolveThemeFontReference };
|
|
@@ -6,6 +6,7 @@ const TWIPS_PER_INCH = 1440;
|
|
|
6
6
|
const EMU_PER_POINT = EMU_PER_INCH / 72;
|
|
7
7
|
const TWIPS_PER_POINT = TWIPS_PER_INCH / 72;
|
|
8
8
|
const HALF_POINTS_PER_POINT = 2;
|
|
9
|
+
const EIGHTH_POINTS_PER_POINT = 8;
|
|
9
10
|
const DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = 100;
|
|
10
11
|
const LINE_UNITS_PER_LINE = 240;
|
|
11
12
|
function emuToPt(emu) {
|
|
@@ -26,6 +27,12 @@ function halfPointsToPt(halfPoints) {
|
|
|
26
27
|
function ptToHalfPoints(pt) {
|
|
27
28
|
return Math.round(pt * 2);
|
|
28
29
|
}
|
|
30
|
+
function eighthPointsToPt(eighthPoints) {
|
|
31
|
+
return eighthPoints / 8;
|
|
32
|
+
}
|
|
33
|
+
function ptToEighthPoints(pt) {
|
|
34
|
+
return Math.round(pt * 8);
|
|
35
|
+
}
|
|
29
36
|
function drawingMlFontSizeToPt(hundredths) {
|
|
30
37
|
return hundredths / 100;
|
|
31
38
|
}
|
|
@@ -37,6 +44,7 @@ function lineUnitsToMultiplier(lineUnits) {
|
|
|
37
44
|
}
|
|
38
45
|
//#endregion
|
|
39
46
|
exports.DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT;
|
|
47
|
+
exports.EIGHTH_POINTS_PER_POINT = EIGHTH_POINTS_PER_POINT;
|
|
40
48
|
exports.EMU_PER_INCH = EMU_PER_INCH;
|
|
41
49
|
exports.EMU_PER_POINT = EMU_PER_POINT;
|
|
42
50
|
exports.HALF_POINTS_PER_POINT = HALF_POINTS_PER_POINT;
|
|
@@ -45,10 +53,12 @@ exports.POINTS_PER_INCH = POINTS_PER_INCH;
|
|
|
45
53
|
exports.TWIPS_PER_INCH = TWIPS_PER_INCH;
|
|
46
54
|
exports.TWIPS_PER_POINT = TWIPS_PER_POINT;
|
|
47
55
|
exports.drawingMlFontSizeToPt = drawingMlFontSizeToPt;
|
|
56
|
+
exports.eighthPointsToPt = eighthPointsToPt;
|
|
48
57
|
exports.emuToPt = emuToPt;
|
|
49
58
|
exports.halfPointsToPt = halfPointsToPt;
|
|
50
59
|
exports.lineUnitsToMultiplier = lineUnitsToMultiplier;
|
|
51
60
|
exports.ptToDrawingMlFontSize = ptToDrawingMlFontSize;
|
|
61
|
+
exports.ptToEighthPoints = ptToEighthPoints;
|
|
52
62
|
exports.ptToEmu = ptToEmu;
|
|
53
63
|
exports.ptToHalfPoints = ptToHalfPoints;
|
|
54
64
|
exports.ptToTwips = ptToTwips;
|
|
@@ -5,6 +5,7 @@ declare const TWIPS_PER_INCH = 1440;
|
|
|
5
5
|
declare const EMU_PER_POINT: number;
|
|
6
6
|
declare const TWIPS_PER_POINT: number;
|
|
7
7
|
declare const HALF_POINTS_PER_POINT = 2;
|
|
8
|
+
declare const EIGHTH_POINTS_PER_POINT = 8;
|
|
8
9
|
declare const DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = 100;
|
|
9
10
|
declare const LINE_UNITS_PER_LINE = 240;
|
|
10
11
|
declare function emuToPt(emu: number): number;
|
|
@@ -13,8 +14,10 @@ declare function twipsToPt(twips: number): number;
|
|
|
13
14
|
declare function ptToTwips(pt: number): number;
|
|
14
15
|
declare function halfPointsToPt(halfPoints: number): number;
|
|
15
16
|
declare function ptToHalfPoints(pt: number): number;
|
|
17
|
+
declare function eighthPointsToPt(eighthPoints: number): number;
|
|
18
|
+
declare function ptToEighthPoints(pt: number): number;
|
|
16
19
|
declare function drawingMlFontSizeToPt(hundredths: number): number;
|
|
17
20
|
declare function ptToDrawingMlFontSize(pt: number): number;
|
|
18
21
|
declare function lineUnitsToMultiplier(lineUnits: number): number;
|
|
19
22
|
//#endregion
|
|
20
|
-
export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
|
|
23
|
+
export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EIGHTH_POINTS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, eighthPointsToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEighthPoints, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
|
|
@@ -5,6 +5,7 @@ declare const TWIPS_PER_INCH = 1440;
|
|
|
5
5
|
declare const EMU_PER_POINT: number;
|
|
6
6
|
declare const TWIPS_PER_POINT: number;
|
|
7
7
|
declare const HALF_POINTS_PER_POINT = 2;
|
|
8
|
+
declare const EIGHTH_POINTS_PER_POINT = 8;
|
|
8
9
|
declare const DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = 100;
|
|
9
10
|
declare const LINE_UNITS_PER_LINE = 240;
|
|
10
11
|
declare function emuToPt(emu: number): number;
|
|
@@ -13,8 +14,10 @@ declare function twipsToPt(twips: number): number;
|
|
|
13
14
|
declare function ptToTwips(pt: number): number;
|
|
14
15
|
declare function halfPointsToPt(halfPoints: number): number;
|
|
15
16
|
declare function ptToHalfPoints(pt: number): number;
|
|
17
|
+
declare function eighthPointsToPt(eighthPoints: number): number;
|
|
18
|
+
declare function ptToEighthPoints(pt: number): number;
|
|
16
19
|
declare function drawingMlFontSizeToPt(hundredths: number): number;
|
|
17
20
|
declare function ptToDrawingMlFontSize(pt: number): number;
|
|
18
21
|
declare function lineUnitsToMultiplier(lineUnits: number): number;
|
|
19
22
|
//#endregion
|
|
20
|
-
export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
|
|
23
|
+
export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EIGHTH_POINTS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, eighthPointsToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEighthPoints, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
|
|
@@ -5,6 +5,7 @@ const TWIPS_PER_INCH = 1440;
|
|
|
5
5
|
const EMU_PER_POINT = EMU_PER_INCH / 72;
|
|
6
6
|
const TWIPS_PER_POINT = TWIPS_PER_INCH / 72;
|
|
7
7
|
const HALF_POINTS_PER_POINT = 2;
|
|
8
|
+
const EIGHTH_POINTS_PER_POINT = 8;
|
|
8
9
|
const DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = 100;
|
|
9
10
|
const LINE_UNITS_PER_LINE = 240;
|
|
10
11
|
function emuToPt(emu) {
|
|
@@ -25,6 +26,12 @@ function halfPointsToPt(halfPoints) {
|
|
|
25
26
|
function ptToHalfPoints(pt) {
|
|
26
27
|
return Math.round(pt * 2);
|
|
27
28
|
}
|
|
29
|
+
function eighthPointsToPt(eighthPoints) {
|
|
30
|
+
return eighthPoints / 8;
|
|
31
|
+
}
|
|
32
|
+
function ptToEighthPoints(pt) {
|
|
33
|
+
return Math.round(pt * 8);
|
|
34
|
+
}
|
|
28
35
|
function drawingMlFontSizeToPt(hundredths) {
|
|
29
36
|
return hundredths / 100;
|
|
30
37
|
}
|
|
@@ -35,4 +42,4 @@ function lineUnitsToMultiplier(lineUnits) {
|
|
|
35
42
|
return lineUnits / 240;
|
|
36
43
|
}
|
|
37
44
|
//#endregion
|
|
38
|
-
export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
|
|
45
|
+
export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EIGHTH_POINTS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, eighthPointsToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEighthPoints, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
|
|
@@ -5,8 +5,11 @@ require("../shared/units.cjs");
|
|
|
5
5
|
const require_typed_xlsx_shared_strings = require("./shared-strings.cjs");
|
|
6
6
|
const require_typed_xlsx_a1 = require("./a1.cjs");
|
|
7
7
|
const require_typed_xlsx_defined_names = require("./defined-names.cjs");
|
|
8
|
+
const require_typed_xlsx_number_format = require("./number-format.cjs");
|
|
8
9
|
const require_typed_xlsx_util = require("./util.cjs");
|
|
9
10
|
const require_typed_xlsx_print_settings = require("./print-settings.cjs");
|
|
11
|
+
const require_typed_xlsx_serial = require("./serial.cjs");
|
|
12
|
+
const require_typed_xlsx_styles = require("./styles.cjs");
|
|
10
13
|
const require_typed_xlsx_units = require("./units.cjs");
|
|
11
14
|
//#region src/typed/xlsx/build.ts
|
|
12
15
|
const SML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
@@ -180,36 +183,46 @@ function buildSharedStringsPart(sharedStrings) {
|
|
|
180
183
|
uniqueCount: String(entries.length)
|
|
181
184
|
}, siElements));
|
|
182
185
|
}
|
|
183
|
-
function buildStylesPart() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
require_xml_fragment.el("
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
186
|
+
function buildStylesPart(cellFormats) {
|
|
187
|
+
const children = [];
|
|
188
|
+
const declarations = cellFormats.declarations();
|
|
189
|
+
if (declarations.length > 0) {
|
|
190
|
+
const numFmtElements = declarations.map((declaration) => require_xml_fragment.el("numFmt", {
|
|
191
|
+
numFmtId: String(declaration.id),
|
|
192
|
+
formatCode: require_xml_entities.encodeXmlText(declaration.code)
|
|
193
|
+
}));
|
|
194
|
+
children.push(require_xml_fragment.el("numFmts", { count: String(numFmtElements.length) }, numFmtElements));
|
|
195
|
+
}
|
|
196
|
+
children.push(require_xml_fragment.el("fonts", { count: "1" }, [require_xml_fragment.el("font", {}, [require_xml_fragment.el("sz", { val: "11" }), require_xml_fragment.el("name", { val: "Calibri" })])]), require_xml_fragment.el("fills", { count: "2" }, [require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "none" })]), require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "gray125" })])]), require_xml_fragment.el("borders", { count: "1" }, [require_xml_fragment.el("border", {}, [
|
|
197
|
+
require_xml_fragment.el("left"),
|
|
198
|
+
require_xml_fragment.el("right"),
|
|
199
|
+
require_xml_fragment.el("top"),
|
|
200
|
+
require_xml_fragment.el("bottom"),
|
|
201
|
+
require_xml_fragment.el("diagonal")
|
|
202
|
+
])]), require_xml_fragment.el("cellStyleXfs", { count: "1" }, [require_xml_fragment.el("xf", {
|
|
203
|
+
numFmtId: "0",
|
|
204
|
+
fontId: "0",
|
|
205
|
+
fillId: "0",
|
|
206
|
+
borderId: "0"
|
|
207
|
+
})]));
|
|
208
|
+
const xfElements = cellFormats.cellFormats().map((numFmtId) => {
|
|
209
|
+
const attrs = {
|
|
210
|
+
numFmtId: String(numFmtId),
|
|
202
211
|
fontId: "0",
|
|
203
212
|
fillId: "0",
|
|
204
213
|
borderId: "0",
|
|
205
214
|
xfId: "0"
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
215
|
+
};
|
|
216
|
+
if (numFmtId !== 0) attrs.applyNumberFormat = require_typed_xlsx_util.writeXmlBool(true);
|
|
217
|
+
return require_xml_fragment.el("xf", attrs);
|
|
218
|
+
});
|
|
219
|
+
children.push(require_xml_fragment.el("cellXfs", { count: String(xfElements.length) }, xfElements));
|
|
220
|
+
children.push(require_xml_fragment.el("cellStyles", { count: "1" }, [require_xml_fragment.el("cellStyle", {
|
|
221
|
+
name: "Normal",
|
|
222
|
+
xfId: "0",
|
|
223
|
+
builtinId: "0"
|
|
224
|
+
})]));
|
|
225
|
+
return xmlPart(require_xml_fragment.el("styleSheet", { xmlns: SML_NS }, children));
|
|
213
226
|
}
|
|
214
227
|
function buildCorePropertiesPart(metadata) {
|
|
215
228
|
const children = [];
|
|
@@ -272,28 +285,24 @@ function buildColsElement(columns) {
|
|
|
272
285
|
}
|
|
273
286
|
function renderCellValue(value, isFormulaResult, sharedStrings) {
|
|
274
287
|
switch (value.kind) {
|
|
275
|
-
case "string":
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
case "percentage":
|
|
286
|
-
case "currency": return { content: String(value.value) };
|
|
288
|
+
case "string": return renderString(value.value, isFormulaResult, sharedStrings);
|
|
289
|
+
case "number": return { content: String(value.value) };
|
|
290
|
+
case "percentage": return {
|
|
291
|
+
content: String(value.value),
|
|
292
|
+
format: require_typed_xlsx_number_format.PERCENTAGE_NUMBER_FORMAT
|
|
293
|
+
};
|
|
294
|
+
case "currency": return {
|
|
295
|
+
content: String(value.value),
|
|
296
|
+
format: require_typed_xlsx_number_format.currencyNumberFormat(value.currency)
|
|
297
|
+
};
|
|
287
298
|
case "boolean": return {
|
|
288
299
|
type: "b",
|
|
289
|
-
content: value.value ? "1" : "0"
|
|
290
|
-
|
|
291
|
-
case "date":
|
|
292
|
-
case "time":
|
|
293
|
-
case "dateTime": return {
|
|
294
|
-
type: "d",
|
|
295
|
-
content: require_xml_entities.encodeXmlText(value.value)
|
|
300
|
+
content: value.value ? "1" : "0",
|
|
301
|
+
format: require_typed_xlsx_number_format.BOOLEAN_NUMBER_FORMAT
|
|
296
302
|
};
|
|
303
|
+
case "date": return renderTemporal(require_typed_xlsx_serial.isoDateToSerial(value.value), value.value, require_typed_xlsx_number_format.DATE_NUMBER_FORMAT, isFormulaResult, sharedStrings);
|
|
304
|
+
case "time": return renderTemporal(require_typed_xlsx_serial.isoTimeToSerial(value.value), value.value, require_typed_xlsx_number_format.TIME_NUMBER_FORMAT, isFormulaResult, sharedStrings);
|
|
305
|
+
case "dateTime": return renderTemporal(require_typed_xlsx_serial.isoDateTimeToSerial(value.value), value.value, require_typed_xlsx_number_format.DATE_TIME_NUMBER_FORMAT, isFormulaResult, sharedStrings);
|
|
297
306
|
case "error": return {
|
|
298
307
|
type: "e",
|
|
299
308
|
content: require_xml_entities.encodeXmlText(value.value)
|
|
@@ -301,21 +310,39 @@ function renderCellValue(value, isFormulaResult, sharedStrings) {
|
|
|
301
310
|
case "empty": return;
|
|
302
311
|
}
|
|
303
312
|
}
|
|
304
|
-
function
|
|
313
|
+
function renderString(text, isFormulaResult, sharedStrings) {
|
|
314
|
+
if (isFormulaResult) return {
|
|
315
|
+
type: "str",
|
|
316
|
+
content: require_xml_entities.encodeXmlText(text)
|
|
317
|
+
};
|
|
318
|
+
return {
|
|
319
|
+
type: "s",
|
|
320
|
+
content: String(sharedStrings.intern(text))
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function renderTemporal(serial, iso, format, isFormulaResult, sharedStrings) {
|
|
324
|
+
if (serial === void 0) return renderString(iso, isFormulaResult, sharedStrings);
|
|
325
|
+
return {
|
|
326
|
+
content: String(serial),
|
|
327
|
+
format
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function buildCellElement(cell, sharedStrings, cellFormats) {
|
|
331
|
+
const children = [];
|
|
332
|
+
const rendered = renderCellValue(cell.value, cell.formula !== void 0, sharedStrings);
|
|
333
|
+
const styleIndex = rendered?.format === void 0 ? 0 : cellFormats.intern(rendered.format);
|
|
305
334
|
const attrs = {
|
|
306
335
|
r: require_typed_xlsx_a1.cellReference(cell.row, cell.column),
|
|
307
|
-
s:
|
|
336
|
+
s: String(styleIndex)
|
|
308
337
|
};
|
|
309
|
-
const children = [];
|
|
310
338
|
if (cell.formula !== void 0) children.push(require_xml_fragment.el("f", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(cell.formula))]));
|
|
311
|
-
const rendered = renderCellValue(cell.value, cell.formula !== void 0, sharedStrings);
|
|
312
339
|
if (rendered !== void 0) {
|
|
313
340
|
if (rendered.type !== void 0) attrs.t = rendered.type;
|
|
314
341
|
children.push(require_xml_fragment.el("v", {}, [require_xml_fragment.txt(rendered.content)]));
|
|
315
342
|
}
|
|
316
343
|
return require_xml_fragment.el("c", attrs, children);
|
|
317
344
|
}
|
|
318
|
-
function buildSheetDataElement(sheet, sharedStrings) {
|
|
345
|
+
function buildSheetDataElement(sheet, sharedStrings, cellFormats) {
|
|
319
346
|
const cellsByRow = /* @__PURE__ */ new Map();
|
|
320
347
|
for (const cell of sheet.cells) {
|
|
321
348
|
const existing = cellsByRow.get(cell.row);
|
|
@@ -335,7 +362,7 @@ function buildSheetDataElement(sheet, sharedStrings) {
|
|
|
335
362
|
}
|
|
336
363
|
if (rowInfo.hidden === true) attrs.hidden = "true";
|
|
337
364
|
}
|
|
338
|
-
return require_xml_fragment.el("row", attrs, cells.map((cell) => buildCellElement(cell, sharedStrings)));
|
|
365
|
+
return require_xml_fragment.el("row", attrs, cells.map((cell) => buildCellElement(cell, sharedStrings, cellFormats)));
|
|
339
366
|
}));
|
|
340
367
|
}
|
|
341
368
|
function buildMergeCellsElement(cells) {
|
|
@@ -421,11 +448,11 @@ function buildBreaksElements(settings) {
|
|
|
421
448
|
}
|
|
422
449
|
return result;
|
|
423
450
|
}
|
|
424
|
-
function buildWorksheetPart(sheet, sharedStrings) {
|
|
451
|
+
function buildWorksheetPart(sheet, sharedStrings, cellFormats) {
|
|
425
452
|
const children = [buildSheetPrElement(sheet.printSettings), require_xml_fragment.el("dimension", { ref: computeDimension(sheet) })];
|
|
426
453
|
const colsElement = buildColsElement(sheet.columns);
|
|
427
454
|
if (colsElement !== void 0) children.push(colsElement);
|
|
428
|
-
children.push(buildSheetDataElement(sheet, sharedStrings));
|
|
455
|
+
children.push(buildSheetDataElement(sheet, sharedStrings, cellFormats));
|
|
429
456
|
const mergeCellsElement = buildMergeCellsElement(sheet.cells);
|
|
430
457
|
if (mergeCellsElement !== void 0) children.push(mergeCellsElement);
|
|
431
458
|
children.push(buildPrintOptionsElement(sheet.printSettings), buildPageMarginsElement(sheet.printSettings), buildPageSetupElement(sheet.printSettings));
|
|
@@ -441,13 +468,14 @@ function buildXlsxPackage(document) {
|
|
|
441
468
|
if (document.kind !== "spreadsheet") throw new Error(`buildXlsxPackage: expected a ContentDocument of kind "spreadsheet", got "${document.kind}"`);
|
|
442
469
|
const sheets = document.sheets;
|
|
443
470
|
const sharedStrings = new require_typed_xlsx_shared_strings.SharedStringTable();
|
|
444
|
-
const
|
|
471
|
+
const cellFormats = new require_typed_xlsx_styles.CellFormatTable();
|
|
472
|
+
const worksheetParts = sheets.map((sheet) => buildWorksheetPart(sheet, sharedStrings, cellFormats));
|
|
445
473
|
const parts = {
|
|
446
474
|
"[Content_Types].xml": buildContentTypesPart(sheets.length),
|
|
447
475
|
"_rels/.rels": buildPackageRelsPart(),
|
|
448
476
|
"xl/workbook.xml": buildWorkbookPart(sheets),
|
|
449
477
|
"xl/_rels/workbook.xml.rels": buildWorkbookRelsPart(sheets.length),
|
|
450
|
-
"xl/styles.xml": buildStylesPart(),
|
|
478
|
+
"xl/styles.xml": buildStylesPart(cellFormats),
|
|
451
479
|
"xl/sharedStrings.xml": buildSharedStringsPart(sharedStrings),
|
|
452
480
|
"docProps/core.xml": buildCorePropertiesPart(document.metadata),
|
|
453
481
|
"docProps/app.xml": buildAppPropertiesPart(document.metadata)
|