ooxml.js 2.5.1 → 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.d.cts +1 -0
- package/dist/typed/pptx/read.d.ts +1 -0
- 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 +93 -60
- package/dist/typed/xlsx/build.js +93 -60
- package/dist/typed/xlsx/content.cjs +93 -22
- package/dist/typed/xlsx/content.js +93 -22
- 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/print-settings.cjs +1 -1
- package/dist/typed/xlsx/print-settings.js +1 -1
- 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 +2 -2
|
@@ -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 = [];
|
|
@@ -260,37 +273,36 @@ function buildColsElement(columns) {
|
|
|
260
273
|
return require_xml_fragment.el("cols", {}, columns.map((column) => {
|
|
261
274
|
const attrs = {
|
|
262
275
|
min: String(column.index + 1),
|
|
263
|
-
max: String(column.index + 1)
|
|
264
|
-
width: require_typed_xlsx_units.ptToColumnWidthChars(column.widthPt).toFixed(2),
|
|
265
|
-
customWidth: "true"
|
|
276
|
+
max: String(column.index + 1)
|
|
266
277
|
};
|
|
278
|
+
if (column.widthPt !== void 0) {
|
|
279
|
+
attrs.width = require_typed_xlsx_units.ptToColumnWidthChars(column.widthPt).toFixed(2);
|
|
280
|
+
attrs.customWidth = "true";
|
|
281
|
+
}
|
|
267
282
|
if (column.hidden === true) attrs.hidden = "true";
|
|
268
283
|
return require_xml_fragment.el("col", attrs);
|
|
269
284
|
}));
|
|
270
285
|
}
|
|
271
286
|
function renderCellValue(value, isFormulaResult, sharedStrings) {
|
|
272
287
|
switch (value.kind) {
|
|
273
|
-
case "string":
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
case "percentage":
|
|
284
|
-
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
|
+
};
|
|
285
298
|
case "boolean": return {
|
|
286
299
|
type: "b",
|
|
287
|
-
content: value.value ? "1" : "0"
|
|
288
|
-
|
|
289
|
-
case "date":
|
|
290
|
-
case "time": return {
|
|
291
|
-
type: "d",
|
|
292
|
-
content: require_xml_entities.encodeXmlText(value.value)
|
|
300
|
+
content: value.value ? "1" : "0",
|
|
301
|
+
format: require_typed_xlsx_number_format.BOOLEAN_NUMBER_FORMAT
|
|
293
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);
|
|
294
306
|
case "error": return {
|
|
295
307
|
type: "e",
|
|
296
308
|
content: require_xml_entities.encodeXmlText(value.value)
|
|
@@ -298,21 +310,39 @@ function renderCellValue(value, isFormulaResult, sharedStrings) {
|
|
|
298
310
|
case "empty": return;
|
|
299
311
|
}
|
|
300
312
|
}
|
|
301
|
-
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);
|
|
302
334
|
const attrs = {
|
|
303
335
|
r: require_typed_xlsx_a1.cellReference(cell.row, cell.column),
|
|
304
|
-
s:
|
|
336
|
+
s: String(styleIndex)
|
|
305
337
|
};
|
|
306
|
-
const children = [];
|
|
307
338
|
if (cell.formula !== void 0) children.push(require_xml_fragment.el("f", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(cell.formula))]));
|
|
308
|
-
const rendered = renderCellValue(cell.value, cell.formula !== void 0, sharedStrings);
|
|
309
339
|
if (rendered !== void 0) {
|
|
310
340
|
if (rendered.type !== void 0) attrs.t = rendered.type;
|
|
311
341
|
children.push(require_xml_fragment.el("v", {}, [require_xml_fragment.txt(rendered.content)]));
|
|
312
342
|
}
|
|
313
343
|
return require_xml_fragment.el("c", attrs, children);
|
|
314
344
|
}
|
|
315
|
-
function buildSheetDataElement(sheet, sharedStrings) {
|
|
345
|
+
function buildSheetDataElement(sheet, sharedStrings, cellFormats) {
|
|
316
346
|
const cellsByRow = /* @__PURE__ */ new Map();
|
|
317
347
|
for (const cell of sheet.cells) {
|
|
318
348
|
const existing = cellsByRow.get(cell.row);
|
|
@@ -326,11 +356,13 @@ function buildSheetDataElement(sheet, sharedStrings) {
|
|
|
326
356
|
const rowInfo = rowInfoByIndex.get(rowIndex);
|
|
327
357
|
const attrs = { r: String(rowIndex + 1) };
|
|
328
358
|
if (rowInfo !== void 0) {
|
|
329
|
-
|
|
330
|
-
|
|
359
|
+
if (rowInfo.heightPt !== void 0) {
|
|
360
|
+
attrs.ht = String(rowInfo.heightPt);
|
|
361
|
+
attrs.customHeight = "true";
|
|
362
|
+
}
|
|
331
363
|
if (rowInfo.hidden === true) attrs.hidden = "true";
|
|
332
364
|
}
|
|
333
|
-
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)));
|
|
334
366
|
}));
|
|
335
367
|
}
|
|
336
368
|
function buildMergeCellsElement(cells) {
|
|
@@ -379,7 +411,7 @@ function buildPageSetupElement(settings) {
|
|
|
379
411
|
attrs.paperWidth = require_typed_xlsx_util.ptToUniversalMeasure(settings.pageSize.widthPt);
|
|
380
412
|
attrs.paperHeight = require_typed_xlsx_util.ptToUniversalMeasure(settings.pageSize.heightPt);
|
|
381
413
|
}
|
|
382
|
-
attrs.scale = String(settings.
|
|
414
|
+
attrs.scale = String(settings.scalePercent ?? 100);
|
|
383
415
|
attrs.fitToWidth = String(settings.fitToPages?.width ?? 1);
|
|
384
416
|
attrs.fitToHeight = String(settings.fitToPages?.height ?? 1);
|
|
385
417
|
attrs.pageOrder = settings.pageOrder;
|
|
@@ -416,11 +448,11 @@ function buildBreaksElements(settings) {
|
|
|
416
448
|
}
|
|
417
449
|
return result;
|
|
418
450
|
}
|
|
419
|
-
function buildWorksheetPart(sheet, sharedStrings) {
|
|
451
|
+
function buildWorksheetPart(sheet, sharedStrings, cellFormats) {
|
|
420
452
|
const children = [buildSheetPrElement(sheet.printSettings), require_xml_fragment.el("dimension", { ref: computeDimension(sheet) })];
|
|
421
453
|
const colsElement = buildColsElement(sheet.columns);
|
|
422
454
|
if (colsElement !== void 0) children.push(colsElement);
|
|
423
|
-
children.push(buildSheetDataElement(sheet, sharedStrings));
|
|
455
|
+
children.push(buildSheetDataElement(sheet, sharedStrings, cellFormats));
|
|
424
456
|
const mergeCellsElement = buildMergeCellsElement(sheet.cells);
|
|
425
457
|
if (mergeCellsElement !== void 0) children.push(mergeCellsElement);
|
|
426
458
|
children.push(buildPrintOptionsElement(sheet.printSettings), buildPageMarginsElement(sheet.printSettings), buildPageSetupElement(sheet.printSettings));
|
|
@@ -436,13 +468,14 @@ function buildXlsxPackage(document) {
|
|
|
436
468
|
if (document.kind !== "spreadsheet") throw new Error(`buildXlsxPackage: expected a ContentDocument of kind "spreadsheet", got "${document.kind}"`);
|
|
437
469
|
const sheets = document.sheets;
|
|
438
470
|
const sharedStrings = new require_typed_xlsx_shared_strings.SharedStringTable();
|
|
439
|
-
const
|
|
471
|
+
const cellFormats = new require_typed_xlsx_styles.CellFormatTable();
|
|
472
|
+
const worksheetParts = sheets.map((sheet) => buildWorksheetPart(sheet, sharedStrings, cellFormats));
|
|
440
473
|
const parts = {
|
|
441
474
|
"[Content_Types].xml": buildContentTypesPart(sheets.length),
|
|
442
475
|
"_rels/.rels": buildPackageRelsPart(),
|
|
443
476
|
"xl/workbook.xml": buildWorkbookPart(sheets),
|
|
444
477
|
"xl/_rels/workbook.xml.rels": buildWorkbookRelsPart(sheets.length),
|
|
445
|
-
"xl/styles.xml": buildStylesPart(),
|
|
478
|
+
"xl/styles.xml": buildStylesPart(cellFormats),
|
|
446
479
|
"xl/sharedStrings.xml": buildSharedStringsPart(sharedStrings),
|
|
447
480
|
"docProps/core.xml": buildCorePropertiesPart(document.metadata),
|
|
448
481
|
"docProps/app.xml": buildAppPropertiesPart(document.metadata)
|