@devmm/puredocs-excel 1.0.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/LICENSE +21 -0
- package/dist/index.cjs +2595 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1016 -0
- package/dist/index.d.ts +1016 -0
- package/dist/index.js +2544 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1016 @@
|
|
|
1
|
+
declare class SharedStringManager {
|
|
2
|
+
#private;
|
|
3
|
+
/** Total number of unique strings. */
|
|
4
|
+
get count(): number;
|
|
5
|
+
/**
|
|
6
|
+
* Adds a string to the table (if not already present) and returns its index.
|
|
7
|
+
* O(1) average case.
|
|
8
|
+
*/
|
|
9
|
+
addOrGet(value: string): number;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the string at the given index.
|
|
12
|
+
* Throws if index is out of range.
|
|
13
|
+
*/
|
|
14
|
+
getString(index: number): string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the string at index, or undefined if not found.
|
|
17
|
+
* Safe alternative to getString().
|
|
18
|
+
*/
|
|
19
|
+
tryGetString(index: number): string | undefined;
|
|
20
|
+
/** Returns true if the string is already in the table. */
|
|
21
|
+
has(value: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Builds the xl/sharedStrings.xml string.
|
|
24
|
+
*/
|
|
25
|
+
buildXml(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Parses an existing xl/sharedStrings.xml and loads strings into the table.
|
|
28
|
+
*/
|
|
29
|
+
loadFromXml(xml: string): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Represents a color for use in Excel styling (fonts, fills, borders).
|
|
34
|
+
* Supports hex, RGB, ARGB, theme, and indexed colors.
|
|
35
|
+
*
|
|
36
|
+
* Port of TVE.PureDocs.Excel.ExcelColor (C#)
|
|
37
|
+
*
|
|
38
|
+
* Key differences from C#:
|
|
39
|
+
* - Constructor is private; use static factory methods
|
|
40
|
+
* - Predefined colors use camelCase (ExcelColor.red vs ExcelColor.Red)
|
|
41
|
+
* - toXmlAttrs() replaces ToOpenXmlColor() — returns plain object for XML serialisation
|
|
42
|
+
*/
|
|
43
|
+
interface ColorXmlAttrs {
|
|
44
|
+
rgb?: string;
|
|
45
|
+
theme?: number;
|
|
46
|
+
tint?: number;
|
|
47
|
+
indexed?: number;
|
|
48
|
+
}
|
|
49
|
+
declare class ExcelColor {
|
|
50
|
+
/** ARGB hex string e.g. "FFFF0000" for opaque red. */
|
|
51
|
+
readonly hex: string | undefined;
|
|
52
|
+
/** Theme color index. */
|
|
53
|
+
readonly theme: number | undefined;
|
|
54
|
+
/** Theme tint (-1.0 to 1.0). */
|
|
55
|
+
readonly tint: number | undefined;
|
|
56
|
+
/** Indexed color value. */
|
|
57
|
+
readonly indexed: number | undefined;
|
|
58
|
+
private constructor();
|
|
59
|
+
/**
|
|
60
|
+
* Creates a color from a hex string.
|
|
61
|
+
* Accepts "#RGB", "#RRGGBB", "RRGGBB", or "AARRGGBB" formats.
|
|
62
|
+
*/
|
|
63
|
+
static fromHex(hex: string): ExcelColor;
|
|
64
|
+
/** Creates a color from RGB values (0–255). Alpha is set to 255 (opaque). */
|
|
65
|
+
static fromRgb(red: number, green: number, blue: number): ExcelColor;
|
|
66
|
+
/** Creates a color from ARGB values (0–255). */
|
|
67
|
+
static fromArgb(alpha: number, red: number, green: number, blue: number): ExcelColor;
|
|
68
|
+
/** Creates a theme color with optional tint value (-1.0 to 1.0). */
|
|
69
|
+
static fromTheme(themeIndex: number, tint?: number): ExcelColor;
|
|
70
|
+
/** Creates an indexed color. */
|
|
71
|
+
static fromIndexed(index: number): ExcelColor;
|
|
72
|
+
static readonly black: ExcelColor;
|
|
73
|
+
static readonly white: ExcelColor;
|
|
74
|
+
static readonly red: ExcelColor;
|
|
75
|
+
static readonly green: ExcelColor;
|
|
76
|
+
static readonly blue: ExcelColor;
|
|
77
|
+
static readonly yellow: ExcelColor;
|
|
78
|
+
static readonly magenta: ExcelColor;
|
|
79
|
+
static readonly cyan: ExcelColor;
|
|
80
|
+
static readonly orange: ExcelColor;
|
|
81
|
+
static readonly purple: ExcelColor;
|
|
82
|
+
static readonly darkRed: ExcelColor;
|
|
83
|
+
static readonly darkGreen: ExcelColor;
|
|
84
|
+
static readonly darkBlue: ExcelColor;
|
|
85
|
+
static readonly lightGray: ExcelColor;
|
|
86
|
+
static readonly darkGray: ExcelColor;
|
|
87
|
+
static readonly gray: ExcelColor;
|
|
88
|
+
static readonly lightBlue: ExcelColor;
|
|
89
|
+
static readonly lightGreen: ExcelColor;
|
|
90
|
+
static readonly lightYellow: ExcelColor;
|
|
91
|
+
static readonly lightPink: ExcelColor;
|
|
92
|
+
static readonly transparent: ExcelColor;
|
|
93
|
+
/** Returns XML attribute key-value pairs for embedding in OOXML elements. */
|
|
94
|
+
toXmlAttrs(): ColorXmlAttrs;
|
|
95
|
+
/** Builds an XML color element string for use inside other elements. */
|
|
96
|
+
toXmlElement(tagName: string): string;
|
|
97
|
+
/** Parses a color from OOXML XML attributes. Returns undefined if no color data. */
|
|
98
|
+
static fromXmlAttrs(attrs: Record<string, string | undefined>): ExcelColor | undefined;
|
|
99
|
+
toString(): string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Font configuration for cell styling.
|
|
104
|
+
* Port of TVE.PureDocs.Excel.ExcelFont (C#)
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
declare enum ExcelUnderline {
|
|
108
|
+
None = "none",
|
|
109
|
+
Single = "single",
|
|
110
|
+
Double = "double",
|
|
111
|
+
SingleAccounting = "singleAccounting",
|
|
112
|
+
DoubleAccounting = "doubleAccounting"
|
|
113
|
+
}
|
|
114
|
+
declare enum ExcelVerticalAlignRun {
|
|
115
|
+
Baseline = "baseline",
|
|
116
|
+
Superscript = "superscript",
|
|
117
|
+
Subscript = "subscript"
|
|
118
|
+
}
|
|
119
|
+
interface ExcelFontOptions {
|
|
120
|
+
name?: string;
|
|
121
|
+
size?: number;
|
|
122
|
+
bold?: boolean;
|
|
123
|
+
italic?: boolean;
|
|
124
|
+
underline?: ExcelUnderline;
|
|
125
|
+
strikethrough?: boolean;
|
|
126
|
+
color?: ExcelColor;
|
|
127
|
+
verticalAlign?: ExcelVerticalAlignRun;
|
|
128
|
+
}
|
|
129
|
+
declare class ExcelFont {
|
|
130
|
+
name?: string;
|
|
131
|
+
size?: number;
|
|
132
|
+
bold?: boolean;
|
|
133
|
+
italic?: boolean;
|
|
134
|
+
underline?: ExcelUnderline;
|
|
135
|
+
strikethrough?: boolean;
|
|
136
|
+
color?: ExcelColor;
|
|
137
|
+
verticalAlign?: ExcelVerticalAlignRun;
|
|
138
|
+
constructor(opts?: ExcelFontOptions);
|
|
139
|
+
toXml(): string;
|
|
140
|
+
/** Parses font from parsed XML child elements. */
|
|
141
|
+
static fromXmlChildren(children: Array<{
|
|
142
|
+
tagName: string;
|
|
143
|
+
attributes: Record<string, string>;
|
|
144
|
+
textContent: string;
|
|
145
|
+
}>): ExcelFont;
|
|
146
|
+
/** Builds a canonical cache key for deduplication in StyleManager. */
|
|
147
|
+
cacheKey(): string;
|
|
148
|
+
clone(): ExcelFont;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Cell fill (background) configuration.
|
|
153
|
+
* Port of TVE.PureDocs.Excel.ExcelFill (C#)
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
declare enum ExcelPatternType {
|
|
157
|
+
None = "none",
|
|
158
|
+
Solid = "solid",
|
|
159
|
+
DarkGray = "darkGray",
|
|
160
|
+
MediumGray = "mediumGray",
|
|
161
|
+
LightGray = "lightGray",
|
|
162
|
+
Gray125 = "gray125",
|
|
163
|
+
Gray0625 = "gray0625",
|
|
164
|
+
DarkHorizontal = "darkHorizontal",
|
|
165
|
+
DarkVertical = "darkVertical",
|
|
166
|
+
DarkDown = "darkDown",
|
|
167
|
+
DarkUp = "darkUp",
|
|
168
|
+
DarkGrid = "darkGrid",
|
|
169
|
+
DarkTrellis = "darkTrellis",
|
|
170
|
+
LightHorizontal = "lightHorizontal",
|
|
171
|
+
LightVertical = "lightVertical",
|
|
172
|
+
LightDown = "lightDown",
|
|
173
|
+
LightUp = "lightUp",
|
|
174
|
+
LightGrid = "lightGrid",
|
|
175
|
+
LightTrellis = "lightTrellis"
|
|
176
|
+
}
|
|
177
|
+
declare class ExcelFill {
|
|
178
|
+
patternType: ExcelPatternType;
|
|
179
|
+
/** Foreground/pattern color — for solid fills this IS the background color. */
|
|
180
|
+
foregroundColor?: ExcelColor;
|
|
181
|
+
/** Background color for pattern fills. */
|
|
182
|
+
backgroundColor?: ExcelColor;
|
|
183
|
+
constructor(patternType?: ExcelPatternType, foregroundColor?: ExcelColor, backgroundColor?: ExcelColor);
|
|
184
|
+
/**
|
|
185
|
+
* Creates a solid fill with the given color.
|
|
186
|
+
* Excel requires the magic indexed(64) background color for solid fills.
|
|
187
|
+
*/
|
|
188
|
+
static solid(color: ExcelColor): ExcelFill;
|
|
189
|
+
/** Creates a pattern fill. */
|
|
190
|
+
static pattern(pattern: ExcelPatternType, foreground: ExcelColor, background?: ExcelColor): ExcelFill;
|
|
191
|
+
/** No fill (default). */
|
|
192
|
+
static readonly none: ExcelFill;
|
|
193
|
+
toXml(): string;
|
|
194
|
+
static fromXmlChildren(children: Array<{
|
|
195
|
+
tagName: string;
|
|
196
|
+
attributes: Record<string, string>;
|
|
197
|
+
children: Array<{
|
|
198
|
+
tagName: string;
|
|
199
|
+
attributes: Record<string, string>;
|
|
200
|
+
}>;
|
|
201
|
+
}>): ExcelFill;
|
|
202
|
+
cacheKey(): string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Border configuration for cells.
|
|
207
|
+
* Port of TVE.PureDocs.Excel.ExcelBorder and ExcelBorderEdge (C#)
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
declare enum ExcelBorderStyle {
|
|
211
|
+
None = "none",
|
|
212
|
+
Thin = "thin",
|
|
213
|
+
Medium = "medium",
|
|
214
|
+
Thick = "thick",
|
|
215
|
+
Dashed = "dashed",
|
|
216
|
+
Dotted = "dotted",
|
|
217
|
+
Double = "double",
|
|
218
|
+
Hair = "hair",
|
|
219
|
+
MediumDashed = "mediumDashed",
|
|
220
|
+
DashDot = "dashDot",
|
|
221
|
+
MediumDashDot = "mediumDashDot",
|
|
222
|
+
DashDotDot = "dashDotDot",
|
|
223
|
+
MediumDashDotDot = "mediumDashDotDot",
|
|
224
|
+
SlantDashDot = "slantDashDot"
|
|
225
|
+
}
|
|
226
|
+
declare class ExcelBorderEdge {
|
|
227
|
+
style: ExcelBorderStyle;
|
|
228
|
+
color?: ExcelColor;
|
|
229
|
+
constructor(style?: ExcelBorderStyle, color?: ExcelColor);
|
|
230
|
+
toXml(tag: string): string;
|
|
231
|
+
static fromXmlElement(el: {
|
|
232
|
+
attributes: Record<string, string>;
|
|
233
|
+
children: Array<{
|
|
234
|
+
tagName: string;
|
|
235
|
+
attributes: Record<string, string>;
|
|
236
|
+
}>;
|
|
237
|
+
}): ExcelBorderEdge;
|
|
238
|
+
cacheKey(): string;
|
|
239
|
+
}
|
|
240
|
+
declare class ExcelBorder {
|
|
241
|
+
left: ExcelBorderEdge;
|
|
242
|
+
right: ExcelBorderEdge;
|
|
243
|
+
top: ExcelBorderEdge;
|
|
244
|
+
bottom: ExcelBorderEdge;
|
|
245
|
+
diagonal: ExcelBorderEdge;
|
|
246
|
+
diagonalDown: boolean;
|
|
247
|
+
diagonalUp: boolean;
|
|
248
|
+
constructor();
|
|
249
|
+
/** Sets all four sides to the same style and color. */
|
|
250
|
+
static box(style: ExcelBorderStyle, color?: ExcelColor): ExcelBorder;
|
|
251
|
+
static bottomOnly(style: ExcelBorderStyle, color?: ExcelColor): ExcelBorder;
|
|
252
|
+
static topOnly(style: ExcelBorderStyle, color?: ExcelColor): ExcelBorder;
|
|
253
|
+
static leftOnly(style: ExcelBorderStyle, color?: ExcelColor): ExcelBorder;
|
|
254
|
+
static rightOnly(style: ExcelBorderStyle, color?: ExcelColor): ExcelBorder;
|
|
255
|
+
static readonly none: ExcelBorder;
|
|
256
|
+
toXml(): string;
|
|
257
|
+
static fromXmlChildren(children: Array<{
|
|
258
|
+
tagName: string;
|
|
259
|
+
attributes: Record<string, string>;
|
|
260
|
+
children: Array<{
|
|
261
|
+
tagName: string;
|
|
262
|
+
attributes: Record<string, string>;
|
|
263
|
+
}>;
|
|
264
|
+
}>, borderAttrs: Record<string, string>): ExcelBorder;
|
|
265
|
+
cacheKey(): string;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Text alignment configuration for cells.
|
|
270
|
+
* Port of TVE.PureDocs.Excel.ExcelAlignment (C#)
|
|
271
|
+
*/
|
|
272
|
+
declare enum ExcelHorizontalAlignment {
|
|
273
|
+
General = "general",
|
|
274
|
+
Left = "left",
|
|
275
|
+
Center = "center",
|
|
276
|
+
Right = "right",
|
|
277
|
+
Fill = "fill",
|
|
278
|
+
Justify = "justify",
|
|
279
|
+
CenterContinuous = "centerContinuous",
|
|
280
|
+
Distributed = "distributed"
|
|
281
|
+
}
|
|
282
|
+
declare enum ExcelVerticalAlignment {
|
|
283
|
+
Top = "top",
|
|
284
|
+
Center = "center",
|
|
285
|
+
Bottom = "bottom",
|
|
286
|
+
Justify = "justify",
|
|
287
|
+
Distributed = "distributed"
|
|
288
|
+
}
|
|
289
|
+
declare enum ExcelReadingOrder {
|
|
290
|
+
ContextDependent = 0,
|
|
291
|
+
LeftToRight = 1,
|
|
292
|
+
RightToLeft = 2
|
|
293
|
+
}
|
|
294
|
+
declare class ExcelAlignment {
|
|
295
|
+
horizontal?: ExcelHorizontalAlignment;
|
|
296
|
+
vertical?: ExcelVerticalAlignment;
|
|
297
|
+
wrapText?: boolean;
|
|
298
|
+
shrinkToFit?: boolean;
|
|
299
|
+
textRotation?: number;
|
|
300
|
+
indent?: number;
|
|
301
|
+
readingOrder?: ExcelReadingOrder;
|
|
302
|
+
toXml(): string;
|
|
303
|
+
static fromXmlAttrs(attrs: Record<string, string>): ExcelAlignment;
|
|
304
|
+
cacheKey(): string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Number format for cell display.
|
|
309
|
+
* Port of TVE.PureDocs.Excel.ExcelNumberFormat (C#)
|
|
310
|
+
*
|
|
311
|
+
* Built-in format IDs (per OOXML spec §18.8.30):
|
|
312
|
+
* 0 = General
|
|
313
|
+
* 1 = 0
|
|
314
|
+
* 2 = 0.00
|
|
315
|
+
* 3 = #,##0
|
|
316
|
+
* 4 = #,##0.00
|
|
317
|
+
* 9 = 0%
|
|
318
|
+
* 10 = 0.00%
|
|
319
|
+
* 11 = 0.00E+00
|
|
320
|
+
* 14 = mm-dd-yy (date)
|
|
321
|
+
* …
|
|
322
|
+
* 49 = @ (text)
|
|
323
|
+
* Custom formats start at ID 164.
|
|
324
|
+
*/
|
|
325
|
+
declare class ExcelNumberFormat {
|
|
326
|
+
readonly formatCode: string;
|
|
327
|
+
readonly formatId: number;
|
|
328
|
+
private constructor();
|
|
329
|
+
/** Creates a number format from a custom format code string. */
|
|
330
|
+
static custom(formatCode: string): ExcelNumberFormat;
|
|
331
|
+
/** Creates from format ID and optional custom formats map. */
|
|
332
|
+
static fromFormatId(formatId: number, customFormats?: Map<number, string>): ExcelNumberFormat;
|
|
333
|
+
static readonly general: ExcelNumberFormat;
|
|
334
|
+
static readonly integer: ExcelNumberFormat;
|
|
335
|
+
static readonly decimal2: ExcelNumberFormat;
|
|
336
|
+
static readonly thousandsSeparator: ExcelNumberFormat;
|
|
337
|
+
static readonly thousandsDecimal2: ExcelNumberFormat;
|
|
338
|
+
static readonly percentage: ExcelNumberFormat;
|
|
339
|
+
static readonly percentageDecimal2: ExcelNumberFormat;
|
|
340
|
+
static readonly scientific: ExcelNumberFormat;
|
|
341
|
+
static readonly fraction: ExcelNumberFormat;
|
|
342
|
+
static readonly fractionTwoDigits: ExcelNumberFormat;
|
|
343
|
+
static readonly shortDate: ExcelNumberFormat;
|
|
344
|
+
static readonly longDate: ExcelNumberFormat;
|
|
345
|
+
static readonly dayMonth: ExcelNumberFormat;
|
|
346
|
+
static readonly monthYear: ExcelNumberFormat;
|
|
347
|
+
static readonly time12h: ExcelNumberFormat;
|
|
348
|
+
static readonly time12hSeconds: ExcelNumberFormat;
|
|
349
|
+
static readonly time24h: ExcelNumberFormat;
|
|
350
|
+
static readonly time24hSeconds: ExcelNumberFormat;
|
|
351
|
+
static readonly dateTime: ExcelNumberFormat;
|
|
352
|
+
static readonly accounting: ExcelNumberFormat;
|
|
353
|
+
static readonly accountingRed: ExcelNumberFormat;
|
|
354
|
+
static readonly accountingDecimal2: ExcelNumberFormat;
|
|
355
|
+
static readonly text: ExcelNumberFormat;
|
|
356
|
+
static readonly currency: ExcelNumberFormat;
|
|
357
|
+
static readonly currencyNoDecimal: ExcelNumberFormat;
|
|
358
|
+
static readonly isoDate: ExcelNumberFormat;
|
|
359
|
+
static readonly isoDateTime: ExcelNumberFormat;
|
|
360
|
+
static readonly phoneNumber: ExcelNumberFormat;
|
|
361
|
+
static readonly zipCode: ExcelNumberFormat;
|
|
362
|
+
/** Returns true if this format code represents a date/time value. */
|
|
363
|
+
isDateFormat(): boolean;
|
|
364
|
+
toString(): string;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Complete cell style configuration with fluent builder API.
|
|
369
|
+
* Port of TVE.PureDocs.Excel.CellStyle (C#)
|
|
370
|
+
*
|
|
371
|
+
* Key difference from C#: method names are camelCase (setBold vs SetBold).
|
|
372
|
+
*/
|
|
373
|
+
|
|
374
|
+
declare class CellStyle {
|
|
375
|
+
#private;
|
|
376
|
+
font?: ExcelFont;
|
|
377
|
+
fill?: ExcelFill;
|
|
378
|
+
border?: ExcelBorder;
|
|
379
|
+
alignment?: ExcelAlignment;
|
|
380
|
+
numberFormat?: ExcelNumberFormat;
|
|
381
|
+
isLocked?: boolean;
|
|
382
|
+
isHidden?: boolean;
|
|
383
|
+
setFontName(name: string): this;
|
|
384
|
+
setFontSize(size: number): this;
|
|
385
|
+
setBold(bold?: boolean): this;
|
|
386
|
+
setItalic(italic?: boolean): this;
|
|
387
|
+
setUnderline(underline?: ExcelUnderline): this;
|
|
388
|
+
setStrikethrough(strikethrough?: boolean): this;
|
|
389
|
+
setFontColor(color: ExcelColor): this;
|
|
390
|
+
setFontColor(hex: string): this;
|
|
391
|
+
setVerticalAlign(align: ExcelVerticalAlignRun): this;
|
|
392
|
+
setBackgroundColor(color: ExcelColor): this;
|
|
393
|
+
setBackgroundColor(hex: string): this;
|
|
394
|
+
setPatternFill(pattern: ExcelPatternType, foreground: ExcelColor, background?: ExcelColor): this;
|
|
395
|
+
setAllBorders(style: ExcelBorderStyle, color?: ExcelColor): this;
|
|
396
|
+
setBorder(border: ExcelBorder): this;
|
|
397
|
+
setLeftBorder(style: ExcelBorderStyle, color?: ExcelColor): this;
|
|
398
|
+
setRightBorder(style: ExcelBorderStyle, color?: ExcelColor): this;
|
|
399
|
+
setTopBorder(style: ExcelBorderStyle, color?: ExcelColor): this;
|
|
400
|
+
setBottomBorder(style: ExcelBorderStyle, color?: ExcelColor): this;
|
|
401
|
+
setHorizontalAlignment(alignment: ExcelHorizontalAlignment): this;
|
|
402
|
+
setVerticalAlignment(alignment: ExcelVerticalAlignment): this;
|
|
403
|
+
setWrapText(wrap?: boolean): this;
|
|
404
|
+
setShrinkToFit(shrink?: boolean): this;
|
|
405
|
+
setTextRotation(degrees: number): this;
|
|
406
|
+
setIndent(indent: number): this;
|
|
407
|
+
setNumberFormat(format: ExcelNumberFormat): this;
|
|
408
|
+
setNumberFormat(formatCode: string): this;
|
|
409
|
+
setLocked(locked?: boolean): this;
|
|
410
|
+
setFormulaHidden(hidden?: boolean): this;
|
|
411
|
+
/** Creates a deep copy of this style. */
|
|
412
|
+
clone(): CellStyle;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Manages the workbook stylesheet — fonts, fills, borders, number formats, cell formats.
|
|
417
|
+
* Handles deduplication and index management.
|
|
418
|
+
*
|
|
419
|
+
* Port of TVE.PureDocs.Excel.StyleManager (C#)
|
|
420
|
+
*
|
|
421
|
+
* Key differences:
|
|
422
|
+
* - Works with parsed XmlElement trees instead of OpenXml SDK objects
|
|
423
|
+
* - Serialises directly to XML strings
|
|
424
|
+
* - No lazy save — isDirty flag still used, caller must call buildStylesXml()
|
|
425
|
+
*/
|
|
426
|
+
|
|
427
|
+
declare class StyleManager {
|
|
428
|
+
#private;
|
|
429
|
+
private fonts;
|
|
430
|
+
private fills;
|
|
431
|
+
private borders;
|
|
432
|
+
private numFmts;
|
|
433
|
+
private cellXfs;
|
|
434
|
+
private fontCache;
|
|
435
|
+
private fillCache;
|
|
436
|
+
private borderCache;
|
|
437
|
+
private numFmtCache;
|
|
438
|
+
private cellXfCache;
|
|
439
|
+
private nextCustomNumFmtId;
|
|
440
|
+
isDirty: boolean;
|
|
441
|
+
constructor();
|
|
442
|
+
/**
|
|
443
|
+
* Returns the cellXf index for the given CellStyle.
|
|
444
|
+
* Creates new font/fill/border entries as needed (with deduplication).
|
|
445
|
+
*/
|
|
446
|
+
getOrCreateCellFormatIndex(style: CellStyle): number;
|
|
447
|
+
/**
|
|
448
|
+
* Reconstructs a CellStyle from a cellXf index.
|
|
449
|
+
* Used by Cell.style getter.
|
|
450
|
+
*/
|
|
451
|
+
getCellStyle(styleIndex: number): CellStyle;
|
|
452
|
+
/** Builds the complete xl/styles.xml string. */
|
|
453
|
+
buildStylesXml(): string;
|
|
454
|
+
/** Loads an existing styles.xml, rebuilding all caches. */
|
|
455
|
+
loadFromXml(stylesXml: string): void;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Represents a single cell in a worksheet.
|
|
460
|
+
* Port of TVE.PureDocs.Excel.Cell (C#)
|
|
461
|
+
*
|
|
462
|
+
* Key differences from C#:
|
|
463
|
+
* - All method names are camelCase
|
|
464
|
+
* - No OpenXml SDK dependency — works with plain XML strings
|
|
465
|
+
* - DateTime uses JavaScript Date
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
/** Possible raw types stored in a cell. */
|
|
469
|
+
type CellValue = string | number | boolean | Date | null;
|
|
470
|
+
/** Internal cell data representation (mirrors what OOXML stores). */
|
|
471
|
+
interface CellData {
|
|
472
|
+
reference: string;
|
|
473
|
+
/** 's' = sharedString, 'n' = number, 'b' = boolean, 'str' = inlineStr */
|
|
474
|
+
dataType?: 's' | 'n' | 'b' | 'str';
|
|
475
|
+
rawValue?: string;
|
|
476
|
+
formula?: string;
|
|
477
|
+
styleIndex: number;
|
|
478
|
+
}
|
|
479
|
+
declare class Cell {
|
|
480
|
+
#private;
|
|
481
|
+
/** @internal */
|
|
482
|
+
constructor(data: CellData, sharedStrings: SharedStringManager, styles: StyleManager);
|
|
483
|
+
/** Cell reference string e.g. "A1". */
|
|
484
|
+
get reference(): string;
|
|
485
|
+
/** 1-based row index. */
|
|
486
|
+
get row(): number;
|
|
487
|
+
/** 1-based column index. */
|
|
488
|
+
get column(): number;
|
|
489
|
+
/** Sets a string value. */
|
|
490
|
+
setValue(value: string): this;
|
|
491
|
+
/** Sets a numeric value. */
|
|
492
|
+
setValue(value: number): this;
|
|
493
|
+
/** Sets a boolean value. */
|
|
494
|
+
setValue(value: boolean): this;
|
|
495
|
+
/** Sets a Date value (stored as OADate number). */
|
|
496
|
+
setValue(value: Date): this;
|
|
497
|
+
/** Clears the cell value (sets to null). */
|
|
498
|
+
setValue(value: null): this;
|
|
499
|
+
/**
|
|
500
|
+
* Gets the typed cell value.
|
|
501
|
+
* Returns string | number | boolean | Date | null.
|
|
502
|
+
* Date detection is based on the cell's number format.
|
|
503
|
+
*/
|
|
504
|
+
getValue(): CellValue;
|
|
505
|
+
/**
|
|
506
|
+
* Returns the display text of the cell value (always a string).
|
|
507
|
+
*/
|
|
508
|
+
getText(): string;
|
|
509
|
+
/**
|
|
510
|
+
* Sets a formula. The leading '=' is optional.
|
|
511
|
+
* Clears any cached value.
|
|
512
|
+
*/
|
|
513
|
+
setFormula(formula: string): this;
|
|
514
|
+
/** Returns the formula text (without leading '='), or null if no formula. */
|
|
515
|
+
getFormula(): string | null;
|
|
516
|
+
/** True if this cell contains a formula. */
|
|
517
|
+
get hasFormula(): boolean;
|
|
518
|
+
/** Gets the current CellStyle. Returns a new CellStyle if no style is set. */
|
|
519
|
+
get style(): CellStyle;
|
|
520
|
+
/** Replaces the entire cell style. */
|
|
521
|
+
set style(value: CellStyle);
|
|
522
|
+
/**
|
|
523
|
+
* Applies style changes via a callback on the current style.
|
|
524
|
+
* Returns this for chaining.
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* cell.applyStyle(s => s.setBold(true).setFontColor(ExcelColor.red))
|
|
528
|
+
*/
|
|
529
|
+
applyStyle(action: (style: CellStyle) => void): this;
|
|
530
|
+
setBold(bold?: boolean): this;
|
|
531
|
+
setItalic(italic?: boolean): this;
|
|
532
|
+
setFontSize(size: number): this;
|
|
533
|
+
setFontColor(color: ExcelColor | string): this;
|
|
534
|
+
setFontName(name: string): this;
|
|
535
|
+
setBackgroundColor(color: ExcelColor | string): this;
|
|
536
|
+
setWrapText(wrap?: boolean): this;
|
|
537
|
+
setHorizontalAlignment(a: ExcelHorizontalAlignment): this;
|
|
538
|
+
setVerticalAlignment(a: ExcelVerticalAlignment): this;
|
|
539
|
+
setAllBorders(style: ExcelBorderStyle, color?: ExcelColor): this;
|
|
540
|
+
setNumberFormat(format: ExcelNumberFormat): this;
|
|
541
|
+
setNumberFormat(formatCode: string): this;
|
|
542
|
+
/** Clears the cell value and formula, preserving style. */
|
|
543
|
+
clear(): void;
|
|
544
|
+
/** Clears the cell value, formula, AND style. */
|
|
545
|
+
clearAll(): void;
|
|
546
|
+
/** @internal Builds the <c> XML element string for this cell. */
|
|
547
|
+
toXml(): string;
|
|
548
|
+
/** @internal Parses a <c> XML element into CellData. */
|
|
549
|
+
static fromXmlElement(el: {
|
|
550
|
+
attributes: Record<string, string>;
|
|
551
|
+
children: Array<{
|
|
552
|
+
tagName: string;
|
|
553
|
+
textContent: string;
|
|
554
|
+
}>;
|
|
555
|
+
}, ref: string): CellData;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/** A part that a drawing anchor references (e.g. `xl/charts/chart1.xml`). */
|
|
559
|
+
interface DrawingDependentPart {
|
|
560
|
+
/** Package-relative path, no leading slash — e.g. `xl/charts/chart1.xml`. */
|
|
561
|
+
readonly path: string;
|
|
562
|
+
/** Full XML content of the part. */
|
|
563
|
+
readonly content: string;
|
|
564
|
+
/** Content type for the `[Content_Types].xml` Override entry. */
|
|
565
|
+
readonly contentType: string;
|
|
566
|
+
/** Relationship type used by the drawing → part relationship. */
|
|
567
|
+
readonly relType: string;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Contributes one anchored object (chart, image, …) to a worksheet's drawing.
|
|
571
|
+
* Implemented by satellite packages; consumed by the core save pipeline.
|
|
572
|
+
*/
|
|
573
|
+
interface DrawingProvider {
|
|
574
|
+
/**
|
|
575
|
+
* Builds the `<xdr:*Anchor>` fragment placed inside `<xdr:wsDr>`.
|
|
576
|
+
* @param relationshipId the id (e.g. `"rId1"`) the anchor must reference for
|
|
577
|
+
* its embedded dependent part.
|
|
578
|
+
*/
|
|
579
|
+
buildAnchorXml(relationshipId: string): string;
|
|
580
|
+
/**
|
|
581
|
+
* Builds the dependent part this drawing references.
|
|
582
|
+
* @param partIndex a workbook-unique 1-based index for building a unique path
|
|
583
|
+
* (e.g. `xl/charts/chart{partIndex}.xml`).
|
|
584
|
+
*/
|
|
585
|
+
buildPart(partIndex: number): DrawingDependentPart;
|
|
586
|
+
}
|
|
587
|
+
/** Relationship id used by a worksheet to reference its single drawing part. */
|
|
588
|
+
declare const WORKSHEET_DRAWING_REL_ID = "rId1";
|
|
589
|
+
/** Wraps anchor fragments into a complete `xl/drawings/drawingN.xml` part. */
|
|
590
|
+
declare function buildDrawingXml(anchorsXml: string): string;
|
|
591
|
+
/** Builds a generic `.rels` part from a list of `<Relationship .../>` strings. */
|
|
592
|
+
declare function buildRelsXml(relationships: readonly string[]): string;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Represents a rectangular range of cells for bulk operations.
|
|
596
|
+
* Port of TVE.PureDocs.Excel.Range (C#)
|
|
597
|
+
*/
|
|
598
|
+
|
|
599
|
+
declare class Range {
|
|
600
|
+
#private;
|
|
601
|
+
constructor(sheet: Worksheet, rangeReference: string);
|
|
602
|
+
/** The range address e.g. "A1:B10". */
|
|
603
|
+
get address(): string;
|
|
604
|
+
/** Number of rows in the range. */
|
|
605
|
+
get rowCount(): number;
|
|
606
|
+
/** Number of columns in the range. */
|
|
607
|
+
get columnCount(): number;
|
|
608
|
+
/**
|
|
609
|
+
* Sets values from a 2D array.
|
|
610
|
+
* Values that exceed the range boundary are silently ignored.
|
|
611
|
+
*/
|
|
612
|
+
setValues(values: CellValue[][]): void;
|
|
613
|
+
/**
|
|
614
|
+
* Gets all cell values as a 2D array (row-major order).
|
|
615
|
+
*/
|
|
616
|
+
getValues(): CellValue[][];
|
|
617
|
+
/** Clears all cells in the range (values only, preserves style). */
|
|
618
|
+
clear(): void;
|
|
619
|
+
/** Auto-fits all columns in the range. */
|
|
620
|
+
autoFit(): void;
|
|
621
|
+
/** Applies a CellStyle to all cells in the range. Returns this for chaining. */
|
|
622
|
+
setStyle(style: CellStyle): this;
|
|
623
|
+
/**
|
|
624
|
+
* Applies style changes to all cells in the range.
|
|
625
|
+
* @example range.applyStyle(s => s.setBold(true).setBackgroundColor(ExcelColor.lightGray))
|
|
626
|
+
*/
|
|
627
|
+
applyStyle(action: (style: CellStyle) => void): this;
|
|
628
|
+
setBold(bold?: boolean): this;
|
|
629
|
+
setFontSize(size: number): this;
|
|
630
|
+
setFontColor(color: ExcelColor | string): this;
|
|
631
|
+
setFontName(name: string): this;
|
|
632
|
+
setBackgroundColor(color: ExcelColor | string): this;
|
|
633
|
+
setAllBorders(style: ExcelBorderStyle, color?: ExcelColor): this;
|
|
634
|
+
setHorizontalAlignment(alignment: ExcelHorizontalAlignment): this;
|
|
635
|
+
setVerticalAlignment(alignment: ExcelVerticalAlignment): this;
|
|
636
|
+
setWrapText(wrap?: boolean): this;
|
|
637
|
+
setNumberFormat(format: ExcelNumberFormat): this;
|
|
638
|
+
setNumberFormat(formatCode: string): this;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Represents a worksheet in an Excel workbook.
|
|
643
|
+
* Port of TVE.PureDocs.Excel.Worksheet (C#)
|
|
644
|
+
*
|
|
645
|
+
* Key differences from C#:
|
|
646
|
+
* - All public methods camelCase
|
|
647
|
+
* - XML parsed/serialised directly — no OpenXml SDK
|
|
648
|
+
* - No CalcChain yet (added later via @devmm/puredocs-excel-formula)
|
|
649
|
+
*/
|
|
650
|
+
|
|
651
|
+
type SheetVisibility = 'visible' | 'hidden' | 'veryHidden';
|
|
652
|
+
declare class Worksheet {
|
|
653
|
+
#private;
|
|
654
|
+
/** @internal */
|
|
655
|
+
constructor(name: string, sharedStrings: SharedStringManager, styles: StyleManager);
|
|
656
|
+
get name(): string;
|
|
657
|
+
set name(value: string);
|
|
658
|
+
/**
|
|
659
|
+
* Gets (or creates) a cell by reference string (e.g. "A1") or 1-based row/col.
|
|
660
|
+
* Creates the row/cell if it doesn't exist.
|
|
661
|
+
*/
|
|
662
|
+
getCell(reference: string): Cell;
|
|
663
|
+
getCell(row: number, column: number): Cell;
|
|
664
|
+
/**
|
|
665
|
+
* Returns a Cell if it exists, or null if the row/cell has not been created.
|
|
666
|
+
* Does NOT create a new cell (read-only access).
|
|
667
|
+
*/
|
|
668
|
+
tryGetCell(reference: string): Cell | null;
|
|
669
|
+
tryGetCell(row: number, column: number): Cell | null;
|
|
670
|
+
/** Shorthand indexer — sheet.cell("A1") or sheet.cell(1, 1). */
|
|
671
|
+
cell(reference: string): Cell;
|
|
672
|
+
cell(row: number, column: number): Cell;
|
|
673
|
+
/** Gets a Range object for bulk operations. */
|
|
674
|
+
getRange(rangeReference: string): Range;
|
|
675
|
+
/** Gets the raw value of a cell (for formula evaluation). */
|
|
676
|
+
getCellValue(reference: string): unknown;
|
|
677
|
+
/**
|
|
678
|
+
* Returns the 1-based extent of populated cells (largest row and column that
|
|
679
|
+
* contain data). Returns zeros for an empty sheet. Useful for snapshotting a
|
|
680
|
+
* sheet into a dense 2D array.
|
|
681
|
+
*/
|
|
682
|
+
get usedBounds(): {
|
|
683
|
+
rowCount: number;
|
|
684
|
+
columnCount: number;
|
|
685
|
+
};
|
|
686
|
+
/** Sets the width of a column (1-based index). */
|
|
687
|
+
setColumnWidth(columnIndex: number, width: number): void;
|
|
688
|
+
/** Auto-fits column width based on content (approximate). */
|
|
689
|
+
autoFitColumn(columnIndex: number): void;
|
|
690
|
+
/** Sets the height of a row (1-based index). */
|
|
691
|
+
setRowHeight(rowIndex: number, height: number): void;
|
|
692
|
+
/** Merges cells in the given range (e.g. "A1:B2"). */
|
|
693
|
+
mergeCells(rangeReference: string): void;
|
|
694
|
+
/** Removes a merge for the given range reference. */
|
|
695
|
+
unmergeCells(rangeReference: string): void;
|
|
696
|
+
/**
|
|
697
|
+
* Freezes rows and/or columns.
|
|
698
|
+
* @param row Number of rows to freeze (0 = none)
|
|
699
|
+
* @param column Number of columns to freeze (0 = none)
|
|
700
|
+
*/
|
|
701
|
+
freezePanes(row: number, column: number): void;
|
|
702
|
+
/** Sets auto-filter on the given range. */
|
|
703
|
+
setAutoFilter(rangeReference: string): void;
|
|
704
|
+
/**
|
|
705
|
+
* Adds a dropdown data validation to a cell range.
|
|
706
|
+
* @param cellRange Range to apply (e.g. "F2:F1000")
|
|
707
|
+
* @param listFormula Formula for the dropdown list (e.g. "'Sheet2'!$A$1:$A$10")
|
|
708
|
+
*/
|
|
709
|
+
addDropdownValidation(cellRange: string, listFormula: string): void;
|
|
710
|
+
/** Sets the visibility state of this worksheet. */
|
|
711
|
+
setVisibility(state: SheetVisibility): void;
|
|
712
|
+
get visibility(): SheetVisibility;
|
|
713
|
+
/**
|
|
714
|
+
* Attaches a drawing provider (e.g. a chart) to this worksheet.
|
|
715
|
+
* Satellite packages such as `@devmm/puredocs-excel-charts` call this; the core
|
|
716
|
+
* save pipeline turns registered providers into valid OOXML drawing/chart parts.
|
|
717
|
+
*/
|
|
718
|
+
addDrawingProvider(provider: DrawingProvider): void;
|
|
719
|
+
/** True when this worksheet has at least one drawing to serialise. */
|
|
720
|
+
get hasDrawings(): boolean;
|
|
721
|
+
/** @internal — drawing providers, consumed by the save pipeline. */
|
|
722
|
+
get drawingProviders(): readonly DrawingProvider[];
|
|
723
|
+
/** Builds the xl/worksheets/sheetN.xml string. */
|
|
724
|
+
buildXml(): string;
|
|
725
|
+
/** Parses xl/worksheets/sheetN.xml and loads cells into memory. */
|
|
726
|
+
loadFromXml(xml: string): void;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
declare class Workbook {
|
|
730
|
+
#private;
|
|
731
|
+
private constructor();
|
|
732
|
+
/**
|
|
733
|
+
* Creates a new empty workbook.
|
|
734
|
+
* Mirrors Workbook.Create() in C#.
|
|
735
|
+
*/
|
|
736
|
+
static create(): Workbook;
|
|
737
|
+
/**
|
|
738
|
+
* Opens an existing workbook from a binary buffer (ArrayBuffer or Uint8Array).
|
|
739
|
+
* Works in both browser and Node.js.
|
|
740
|
+
* Mirrors Workbook.Open(stream) in C#.
|
|
741
|
+
*/
|
|
742
|
+
static fromBuffer(buffer: ArrayBuffer | Uint8Array): Workbook;
|
|
743
|
+
/**
|
|
744
|
+
* Opens an existing workbook from a file path (Node.js only).
|
|
745
|
+
* Mirrors Workbook.Open(filePath) in C#.
|
|
746
|
+
*/
|
|
747
|
+
static fromFile(filePath: string): Promise<Workbook>;
|
|
748
|
+
/**
|
|
749
|
+
* Collection of worksheets (read-only array view).
|
|
750
|
+
* Access by index: workbook.worksheets[0]
|
|
751
|
+
* Access by name: workbook.worksheets.find(s => s.name === 'Sheet1')
|
|
752
|
+
*/
|
|
753
|
+
get worksheets(): readonly Worksheet[];
|
|
754
|
+
/**
|
|
755
|
+
* Adds a new worksheet with the given name and returns it.
|
|
756
|
+
* Mirrors workbook.AddWorksheet(name) in C#.
|
|
757
|
+
*/
|
|
758
|
+
addWorksheet(name: string): Worksheet;
|
|
759
|
+
/**
|
|
760
|
+
* Returns a worksheet by name. Throws if not found.
|
|
761
|
+
*/
|
|
762
|
+
getWorksheet(name: string): Worksheet;
|
|
763
|
+
/**
|
|
764
|
+
* Serialises the workbook to a Uint8Array (xlsx binary).
|
|
765
|
+
* Mirrors workbook.SaveAs(stream) in C#.
|
|
766
|
+
* Works in browser and Node.js.
|
|
767
|
+
*/
|
|
768
|
+
saveAsBuffer(): Uint8Array;
|
|
769
|
+
/**
|
|
770
|
+
* Saves the workbook to a file (Node.js only).
|
|
771
|
+
* Mirrors workbook.SaveAs(filePath) in C#.
|
|
772
|
+
*/
|
|
773
|
+
saveToFile(filePath: string): Promise<void>;
|
|
774
|
+
/** Releases resources. The workbook should not be used after this call. */
|
|
775
|
+
close(): void;
|
|
776
|
+
/** Symbol.dispose support for `using` keyword (TypeScript 5.2+). */
|
|
777
|
+
[Symbol.dispose](): void;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Utility for converting between cell references (e.g. "A1") and
|
|
782
|
+
* 1-based row/column indices.
|
|
783
|
+
*
|
|
784
|
+
* Port of TVE.PureDocs.Excel.CellReference (C#)
|
|
785
|
+
*/
|
|
786
|
+
interface ParsedCellRef {
|
|
787
|
+
readonly row: number;
|
|
788
|
+
readonly column: number;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Parses a cell reference string into 1-based row and column indices.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* parseCellRef("A1") // { row: 1, column: 1 }
|
|
795
|
+
* parseCellRef("B10") // { row: 10, column: 2 }
|
|
796
|
+
* parseCellRef("AA1") // { row: 1, column: 27 }
|
|
797
|
+
* parseCellRef("$B$2") // { row: 2, column: 2 } — $ stripped
|
|
798
|
+
*/
|
|
799
|
+
declare function parseCellRef(cellReference: string): ParsedCellRef;
|
|
800
|
+
/**
|
|
801
|
+
* Converts 1-based row and column indices to a cell reference string.
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* cellRefFromRowCol(1, 1) // "A1"
|
|
805
|
+
* cellRefFromRowCol(10, 2) // "B10"
|
|
806
|
+
* cellRefFromRowCol(1, 27) // "AA1"
|
|
807
|
+
*/
|
|
808
|
+
declare function cellRefFromRowCol(row: number, column: number): string;
|
|
809
|
+
/**
|
|
810
|
+
* Converts a 1-based column index to its letter representation.
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* columnLetter(1) // "A"
|
|
814
|
+
* columnLetter(26) // "Z"
|
|
815
|
+
* columnLetter(27) // "AA"
|
|
816
|
+
*/
|
|
817
|
+
declare function columnLetter(column: number): string;
|
|
818
|
+
/**
|
|
819
|
+
* Converts a column letter string to a 1-based column number.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* columnNumber("A") // 1
|
|
823
|
+
* columnNumber("Z") // 26
|
|
824
|
+
* columnNumber("AA") // 27
|
|
825
|
+
*/
|
|
826
|
+
declare function columnNumber(letters: string): number;
|
|
827
|
+
/**
|
|
828
|
+
* Parses a range reference string like "A1:B10" into start/end coordinates.
|
|
829
|
+
*/
|
|
830
|
+
declare function parseRangeRef(rangeReference: string): {
|
|
831
|
+
startRow: number;
|
|
832
|
+
startColumn: number;
|
|
833
|
+
endRow: number;
|
|
834
|
+
endColumn: number;
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* OLE Automation Date (OADate) helpers.
|
|
839
|
+
*
|
|
840
|
+
* Excel stores dates as floating-point numbers where:
|
|
841
|
+
* - The integer part = number of days since Dec 30, 1899 (OADate epoch)
|
|
842
|
+
* - The fractional part = time of day (0.5 = noon)
|
|
843
|
+
*
|
|
844
|
+
* Note: Excel has a known bug treating 1900 as a leap year (day 60 = Feb 29 1900),
|
|
845
|
+
* which never existed. This implementation matches Excel's behaviour exactly.
|
|
846
|
+
*/
|
|
847
|
+
/**
|
|
848
|
+
* Converts a JavaScript Date to an Excel OADate serial number.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* toOADate(new Date(1900, 0, 1)) // 1
|
|
852
|
+
* toOADate(new Date(2025, 0, 1)) // 45658
|
|
853
|
+
*/
|
|
854
|
+
declare function toOADate(date: Date): number;
|
|
855
|
+
/**
|
|
856
|
+
* Converts an Excel OADate serial number to a JavaScript Date.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* fromOADate(1) // Jan 1, 1900
|
|
860
|
+
* fromOADate(45658) // Jan 1, 2025
|
|
861
|
+
*/
|
|
862
|
+
declare function fromOADate(oaDate: number): Date;
|
|
863
|
+
/**
|
|
864
|
+
* Returns true if the given number format ID represents a date/time value.
|
|
865
|
+
*/
|
|
866
|
+
declare function isDateFormatId(formatId: number): boolean;
|
|
867
|
+
/**
|
|
868
|
+
* Returns true if the format code string contains date/time patterns.
|
|
869
|
+
*/
|
|
870
|
+
declare function isDateFormatCode(formatCode: string): boolean;
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Cross-platform XML parser.
|
|
874
|
+
*
|
|
875
|
+
* Uses the browser DOMParser when available; otherwise (Node.js, Deno, Bun without a
|
|
876
|
+
* DOM global) it uses a built-in char-scanning parser. The built-in parser handles the
|
|
877
|
+
* subset of XML that OOXML produces: nested/self-closing elements, attributes, text,
|
|
878
|
+
* CDATA sections, processing instructions and comments, plus standard entity decoding.
|
|
879
|
+
* It is deliberately not a general-purpose XML parser.
|
|
880
|
+
*/
|
|
881
|
+
type XmlElement = {
|
|
882
|
+
readonly tagName: string;
|
|
883
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
884
|
+
readonly children: XmlElement[];
|
|
885
|
+
readonly textContent: string;
|
|
886
|
+
};
|
|
887
|
+
/**
|
|
888
|
+
* Parses an XML string into a simple XmlElement tree.
|
|
889
|
+
*/
|
|
890
|
+
declare function parseXml(xmlString: string): XmlElement;
|
|
891
|
+
/**
|
|
892
|
+
* Decodes a Uint8Array to a UTF-8 string.
|
|
893
|
+
*/
|
|
894
|
+
declare function decodeUtf8(bytes: Uint8Array): string;
|
|
895
|
+
/**
|
|
896
|
+
* Encodes a string to UTF-8 bytes.
|
|
897
|
+
*/
|
|
898
|
+
declare function encodeUtf8(str: string): Uint8Array;
|
|
899
|
+
/**
|
|
900
|
+
* Queries all descendant elements matching a local tag name.
|
|
901
|
+
* Handles namespace-prefixed tags (e.g. "a:t" matches tagName ending in ":t" or equal to "t").
|
|
902
|
+
*/
|
|
903
|
+
declare function getElementsByTagName(root: XmlElement, localName: string): XmlElement[];
|
|
904
|
+
/**
|
|
905
|
+
* Gets a named attribute value, handling namespace prefixes.
|
|
906
|
+
* Tries exact match first, then suffix match (e.g. "r:id" → looks for "r:id" or "id").
|
|
907
|
+
*/
|
|
908
|
+
declare function getAttr(el: XmlElement, name: string): string | undefined;
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Lightweight XML builder for OOXML document parts.
|
|
912
|
+
* Produces well-formed XML strings without external dependencies.
|
|
913
|
+
*/
|
|
914
|
+
/** Escapes special XML characters in an attribute value or text content. */
|
|
915
|
+
declare function escapeXml(value: string): string;
|
|
916
|
+
type XmlAttrs = Record<string, string | number | boolean | undefined>;
|
|
917
|
+
declare class XmlBuilder {
|
|
918
|
+
private readonly parts;
|
|
919
|
+
/** Appends the XML declaration header. */
|
|
920
|
+
xmlDeclaration(): this;
|
|
921
|
+
/** Opens a tag with optional attributes. */
|
|
922
|
+
open(tag: string, attrs?: XmlAttrs): this;
|
|
923
|
+
/** Closes a tag. */
|
|
924
|
+
close(tag: string): this;
|
|
925
|
+
/** Writes a self-closing tag. */
|
|
926
|
+
self(tag: string, attrs?: XmlAttrs): this;
|
|
927
|
+
/** Writes a tag with text content. */
|
|
928
|
+
text(tag: string, content: string, attrs?: XmlAttrs): this;
|
|
929
|
+
/** Writes raw (pre-escaped) XML — use with caution. */
|
|
930
|
+
raw(xml: string): this;
|
|
931
|
+
/** Returns the complete XML string. */
|
|
932
|
+
toString(): string;
|
|
933
|
+
/** Returns UTF-8 encoded bytes. */
|
|
934
|
+
toBytes(): Uint8Array;
|
|
935
|
+
}
|
|
936
|
+
/** Convenience factory. */
|
|
937
|
+
declare function xml(): XmlBuilder;
|
|
938
|
+
declare const NS: {
|
|
939
|
+
readonly spreadsheetml: "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
940
|
+
readonly relationships: "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
941
|
+
readonly relationshipsPackage: "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
942
|
+
readonly drawingml: "http://schemas.openxmlformats.org/drawingml/2006/main";
|
|
943
|
+
readonly spreadsheetDrawing: "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing";
|
|
944
|
+
readonly contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types";
|
|
945
|
+
readonly coreProperties: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
|
|
946
|
+
};
|
|
947
|
+
declare const REL_TYPES: {
|
|
948
|
+
readonly officeDocument: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
|
|
949
|
+
readonly worksheet: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
|
|
950
|
+
readonly sharedStrings: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
|
|
951
|
+
readonly styles: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
|
|
952
|
+
readonly chart: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
|
|
953
|
+
readonly drawing: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing";
|
|
954
|
+
readonly hyperlink: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
|
|
955
|
+
};
|
|
956
|
+
declare const CONTENT_TYPES: {
|
|
957
|
+
readonly workbook: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
|
|
958
|
+
readonly worksheet: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
|
|
959
|
+
readonly sharedStrings: "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
|
|
960
|
+
readonly styles: "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml";
|
|
961
|
+
readonly drawing: "application/vnd.openxmlformats-officedocument.drawing+xml";
|
|
962
|
+
readonly chart: "application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
|
|
963
|
+
readonly relationships: "application/vnd.openxmlformats-package.relationships+xml";
|
|
964
|
+
readonly coreProperties: "application/vnd.openxmlformats-package.core-properties+xml";
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Represents the contents of an unzipped xlsx file.
|
|
969
|
+
* Keys are file paths within the archive (e.g. "xl/workbook.xml").
|
|
970
|
+
* Values are raw UTF-8 bytes.
|
|
971
|
+
*/
|
|
972
|
+
type ZipEntries = Map<string, Uint8Array>;
|
|
973
|
+
/**
|
|
974
|
+
* Unzips an xlsx file buffer into a map of path → bytes.
|
|
975
|
+
*
|
|
976
|
+
* @param buffer - ArrayBuffer or Uint8Array of the xlsx file
|
|
977
|
+
* @returns Map of file paths to their raw bytes
|
|
978
|
+
*/
|
|
979
|
+
declare function unzipXlsx(buffer: ArrayBuffer | Uint8Array): ZipEntries;
|
|
980
|
+
/**
|
|
981
|
+
* Reads and decodes a UTF-8 text entry from a zip archive.
|
|
982
|
+
* Returns undefined if the entry does not exist.
|
|
983
|
+
*/
|
|
984
|
+
declare function readXmlEntry(entries: ZipEntries, path: string): string | undefined;
|
|
985
|
+
/**
|
|
986
|
+
* Reads and decodes a UTF-8 text entry, throwing if missing.
|
|
987
|
+
*/
|
|
988
|
+
declare function requireXmlEntry(entries: ZipEntries, path: string): string;
|
|
989
|
+
/**
|
|
990
|
+
* Returns all entry paths that match the given prefix.
|
|
991
|
+
* Useful for listing worksheets: prefix = "xl/worksheets/".
|
|
992
|
+
*/
|
|
993
|
+
declare function listEntries(entries: ZipEntries, prefix: string): string[];
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Represents the file entries to be zipped.
|
|
997
|
+
* Keys are paths within the archive, values are either bytes or a UTF-8 string.
|
|
998
|
+
*/
|
|
999
|
+
type ZipInput = Map<string, Uint8Array | string>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Zips a collection of file entries into an xlsx-compatible buffer.
|
|
1002
|
+
*
|
|
1003
|
+
* @param entries - Map of path → content (string auto-encoded to UTF-8)
|
|
1004
|
+
* @returns Uint8Array of the resulting ZIP file
|
|
1005
|
+
*/
|
|
1006
|
+
declare function zipXlsx(entries: ZipInput): Uint8Array;
|
|
1007
|
+
/**
|
|
1008
|
+
* Helper to add or update a UTF-8 text entry.
|
|
1009
|
+
*/
|
|
1010
|
+
declare function setXmlEntry(entries: ZipInput, path: string, xml: string): void;
|
|
1011
|
+
/**
|
|
1012
|
+
* Helper to add or update a binary entry.
|
|
1013
|
+
*/
|
|
1014
|
+
declare function setBinaryEntry(entries: ZipInput, path: string, bytes: Uint8Array): void;
|
|
1015
|
+
|
|
1016
|
+
export { CONTENT_TYPES, Cell, type CellData, CellStyle, type CellValue, type ColorXmlAttrs, type DrawingDependentPart, type DrawingProvider, ExcelAlignment, ExcelBorder, ExcelBorderEdge, ExcelBorderStyle, ExcelColor, ExcelFill, ExcelFont, type ExcelFontOptions, ExcelHorizontalAlignment, ExcelNumberFormat, ExcelPatternType, ExcelReadingOrder, ExcelUnderline, ExcelVerticalAlignRun, ExcelVerticalAlignment, NS, type ParsedCellRef, REL_TYPES, Range, type SheetVisibility, StyleManager, WORKSHEET_DRAWING_REL_ID, Workbook, Worksheet, type XmlAttrs, XmlBuilder, type XmlElement, type ZipEntries, type ZipInput, buildDrawingXml, buildRelsXml, cellRefFromRowCol, columnLetter, columnNumber, decodeUtf8, encodeUtf8, escapeXml, fromOADate, getAttr, getElementsByTagName, isDateFormatCode, isDateFormatId, listEntries, parseCellRef, parseRangeRef, parseXml, readXmlEntry, requireXmlEntry, setBinaryEntry, setXmlEntry, toOADate, unzipXlsx, xml, zipXlsx };
|