to-spreadsheet 1.2.0 → 1.3.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 +119 -1
- package/lib/index.d.ts +22 -3
- package/lib/index.js +67 -1
- package/lib/util.d.ts +6 -2
- package/lib/util.js +35 -2
- package/lib/xl/styles.xml.js +23 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,7 +145,7 @@ const data = [
|
|
|
145
145
|
- [x] Cell borders
|
|
146
146
|
- [x] Cell styling (background colors, foreground colors, dates)
|
|
147
147
|
- [x] Date cells with proper Excel formatting
|
|
148
|
-
- [
|
|
148
|
+
- [x] Cell alignment (horizontal and vertical)
|
|
149
149
|
- [ ] Sheet styling
|
|
150
150
|
|
|
151
151
|
## Cell Borders
|
|
@@ -290,3 +290,121 @@ Colors should be specified in hex format:
|
|
|
290
290
|
- `#000000` - Black
|
|
291
291
|
- `#FFFFFF` - White
|
|
292
292
|
- `#CCCCCC` - Light gray
|
|
293
|
+
|
|
294
|
+
## Cell Alignment
|
|
295
|
+
|
|
296
|
+
You can align cell content both horizontally and vertically:
|
|
297
|
+
|
|
298
|
+
### Basic Alignment Usage
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
import {
|
|
302
|
+
generateExcel,
|
|
303
|
+
createHorizontallyAlignedCell,
|
|
304
|
+
createVerticallyAlignedCell,
|
|
305
|
+
createAlignedCell,
|
|
306
|
+
createCenteredCell,
|
|
307
|
+
HorizontalAlignment,
|
|
308
|
+
VerticalAlignment
|
|
309
|
+
} from 'to-spreadsheet/lib/index';
|
|
310
|
+
|
|
311
|
+
const data = [
|
|
312
|
+
{
|
|
313
|
+
title: 'AlignmentDemo',
|
|
314
|
+
content: [
|
|
315
|
+
[
|
|
316
|
+
'Feature',
|
|
317
|
+
'Horizontal',
|
|
318
|
+
'Vertical',
|
|
319
|
+
'Both'
|
|
320
|
+
],
|
|
321
|
+
[
|
|
322
|
+
'Left Align',
|
|
323
|
+
createHorizontallyAlignedCell('Left Text', HorizontalAlignment.left),
|
|
324
|
+
createVerticallyAlignedCell('Top Text', VerticalAlignment.top),
|
|
325
|
+
createAlignedCell('Top-Left', HorizontalAlignment.left, VerticalAlignment.top)
|
|
326
|
+
],
|
|
327
|
+
[
|
|
328
|
+
'Center Align',
|
|
329
|
+
createHorizontallyAlignedCell('Center Text', HorizontalAlignment.center),
|
|
330
|
+
createVerticallyAlignedCell('Center Text', VerticalAlignment.center),
|
|
331
|
+
createCenteredCell('Full Center')
|
|
332
|
+
],
|
|
333
|
+
[
|
|
334
|
+
'Right Align',
|
|
335
|
+
createHorizontallyAlignedCell('Right Text', HorizontalAlignment.right),
|
|
336
|
+
createVerticallyAlignedCell('Bottom Text', VerticalAlignment.bottom),
|
|
337
|
+
createAlignedCell('Bottom-Right', HorizontalAlignment.right, VerticalAlignment.bottom)
|
|
338
|
+
]
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
];
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Horizontal Alignment Options
|
|
345
|
+
|
|
346
|
+
- `HorizontalAlignment.general` - General alignment (Excel default)
|
|
347
|
+
- `HorizontalAlignment.left` - Left alignment
|
|
348
|
+
- `HorizontalAlignment.center` - Center alignment
|
|
349
|
+
- `HorizontalAlignment.right` - Right alignment
|
|
350
|
+
- `HorizontalAlignment.fill` - Fill alignment
|
|
351
|
+
- `HorizontalAlignment.justify` - Justify alignment
|
|
352
|
+
- `HorizontalAlignment.centerContinuous` - Center across selection
|
|
353
|
+
- `HorizontalAlignment.distributed` - Distributed alignment
|
|
354
|
+
|
|
355
|
+
### Vertical Alignment Options
|
|
356
|
+
|
|
357
|
+
- `VerticalAlignment.top` - Top alignment
|
|
358
|
+
- `VerticalAlignment.center` - Center alignment
|
|
359
|
+
- `VerticalAlignment.bottom` - Bottom alignment
|
|
360
|
+
- `VerticalAlignment.justify` - Justify alignment
|
|
361
|
+
- `VerticalAlignment.distributed` - Distributed alignment
|
|
362
|
+
|
|
363
|
+
### Alignment Helper Functions
|
|
364
|
+
|
|
365
|
+
- `createHorizontallyAlignedCell(value, alignment)` - Creates cell with horizontal alignment
|
|
366
|
+
- `createVerticallyAlignedCell(value, alignment)` - Creates cell with vertical alignment
|
|
367
|
+
- `createAlignedCell(value, horizontal, vertical)` - Creates cell with both alignments
|
|
368
|
+
- `createCenteredCell(value)` - Creates center-aligned cell (convenience function)
|
|
369
|
+
|
|
370
|
+
### Combined with Other Features
|
|
371
|
+
|
|
372
|
+
Alignment works seamlessly with all other styling features:
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
import {
|
|
376
|
+
createStyledCell,
|
|
377
|
+
HorizontalAlignment,
|
|
378
|
+
VerticalAlignment,
|
|
379
|
+
createAllBorders,
|
|
380
|
+
BorderStyle
|
|
381
|
+
} from 'to-spreadsheet/lib/index';
|
|
382
|
+
|
|
383
|
+
const data = [
|
|
384
|
+
{
|
|
385
|
+
title: 'ComplexStyling',
|
|
386
|
+
content: [
|
|
387
|
+
[
|
|
388
|
+
// Full styling with alignment, colors, and borders
|
|
389
|
+
createStyledCell('Complete Style', {
|
|
390
|
+
horizontalAlignment: HorizontalAlignment.center,
|
|
391
|
+
verticalAlignment: VerticalAlignment.center,
|
|
392
|
+
backgroundColor: '#CCFFCC',
|
|
393
|
+
foregroundColor: '#FF0000',
|
|
394
|
+
border: createAllBorders(BorderStyle.thick, '#000000')
|
|
395
|
+
}),
|
|
396
|
+
|
|
397
|
+
// Aligned date cell
|
|
398
|
+
createDateCell(new Date(), {
|
|
399
|
+
horizontalAlignment: HorizontalAlignment.right,
|
|
400
|
+
verticalAlignment: VerticalAlignment.center,
|
|
401
|
+
backgroundColor: '#FFFFCC'
|
|
402
|
+
}),
|
|
403
|
+
|
|
404
|
+
// Simple centered text
|
|
405
|
+
createCenteredCell('Centered')
|
|
406
|
+
]
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
];
|
|
410
|
+
```
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateExcel, EnvironmentType } from "./generate-excel";
|
|
2
|
-
import { SkipCell, skipCell, Equation, writeEquation, createBorder, createAllBorders, createTopBorder, createBottomBorder, createLeftBorder, createRightBorder, createStyledCell, createBorderedCell, createDateCell, createBorderedDateCell, createBackgroundCell, createForegroundCell, createColoredCell, createBackgroundDateCell } from "./util";
|
|
2
|
+
import { SkipCell, skipCell, Equation, writeEquation, createBorder, createAllBorders, createTopBorder, createBottomBorder, createLeftBorder, createRightBorder, createStyledCell, createBorderedCell, createDateCell, createBorderedDateCell, createBackgroundCell, createForegroundCell, createColoredCell, createBackgroundDateCell, createHorizontallyAlignedCell, createVerticallyAlignedCell, createAlignedCell, createCenteredCell } from "./util";
|
|
3
3
|
declare enum ICellType {
|
|
4
4
|
string = "s",
|
|
5
5
|
number = "n",
|
|
@@ -16,6 +16,23 @@ declare enum BorderStyle {
|
|
|
16
16
|
dotted = "dotted",
|
|
17
17
|
dashed = "dashed"
|
|
18
18
|
}
|
|
19
|
+
declare enum HorizontalAlignment {
|
|
20
|
+
general = "general",
|
|
21
|
+
left = "left",
|
|
22
|
+
center = "center",
|
|
23
|
+
right = "right",
|
|
24
|
+
fill = "fill",
|
|
25
|
+
justify = "justify",
|
|
26
|
+
centerContinuous = "centerContinuous",
|
|
27
|
+
distributed = "distributed"
|
|
28
|
+
}
|
|
29
|
+
declare enum VerticalAlignment {
|
|
30
|
+
top = "top",
|
|
31
|
+
center = "center",
|
|
32
|
+
bottom = "bottom",
|
|
33
|
+
justify = "justify",
|
|
34
|
+
distributed = "distributed"
|
|
35
|
+
}
|
|
19
36
|
interface IBorder {
|
|
20
37
|
top?: BorderStyle;
|
|
21
38
|
right?: BorderStyle;
|
|
@@ -27,6 +44,8 @@ interface ICellStyle {
|
|
|
27
44
|
border?: IBorder;
|
|
28
45
|
backgroundColor?: string;
|
|
29
46
|
foregroundColor?: string;
|
|
47
|
+
horizontalAlignment?: HorizontalAlignment;
|
|
48
|
+
verticalAlignment?: VerticalAlignment;
|
|
30
49
|
}
|
|
31
50
|
interface ICellString {
|
|
32
51
|
type: ICellType.string;
|
|
@@ -68,7 +87,7 @@ interface IPage {
|
|
|
68
87
|
title: string;
|
|
69
88
|
content: (string | number | undefined | SkipCell | Equation | ICell)[][];
|
|
70
89
|
}
|
|
71
|
-
export { ICell, ISheet, IWorkbook, IRows, ICellType, IPage, BorderStyle, IBorder, ICellStyle, ICellDate };
|
|
90
|
+
export { ICell, ISheet, IWorkbook, IRows, ICellType, IPage, BorderStyle, IBorder, ICellStyle, ICellDate, HorizontalAlignment, VerticalAlignment };
|
|
72
91
|
declare const sampleData: ({
|
|
73
92
|
title: string;
|
|
74
93
|
content: (string[] | (number | Equation)[])[];
|
|
@@ -82,4 +101,4 @@ declare const sampleData: ({
|
|
|
82
101
|
title: string;
|
|
83
102
|
content: (string | number | ICell)[][];
|
|
84
103
|
})[];
|
|
85
|
-
export { generateExcel, sampleData, EnvironmentType, skipCell, writeEquation, createBorder, createAllBorders, createTopBorder, createBottomBorder, createLeftBorder, createRightBorder, createStyledCell, createBorderedCell, createDateCell, createBorderedDateCell, createBackgroundCell, createForegroundCell, createColoredCell, createBackgroundDateCell };
|
|
104
|
+
export { generateExcel, sampleData, EnvironmentType, skipCell, writeEquation, createBorder, createAllBorders, createTopBorder, createBottomBorder, createLeftBorder, createRightBorder, createStyledCell, createBorderedCell, createDateCell, createBorderedDateCell, createBackgroundCell, createForegroundCell, createColoredCell, createBackgroundDateCell, createHorizontallyAlignedCell, createVerticallyAlignedCell, createAlignedCell, createCenteredCell };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createBackgroundDateCell = exports.createColoredCell = exports.createForegroundCell = exports.createBackgroundCell = exports.createBorderedDateCell = exports.createDateCell = exports.createBorderedCell = exports.createStyledCell = exports.createRightBorder = exports.createLeftBorder = exports.createBottomBorder = exports.createTopBorder = exports.createAllBorders = exports.createBorder = exports.writeEquation = exports.skipCell = exports.EnvironmentType = exports.sampleData = exports.generateExcel = exports.BorderStyle = exports.ICellType = void 0;
|
|
3
|
+
exports.createCenteredCell = exports.createAlignedCell = exports.createVerticallyAlignedCell = exports.createHorizontallyAlignedCell = exports.createBackgroundDateCell = exports.createColoredCell = exports.createForegroundCell = exports.createBackgroundCell = exports.createBorderedDateCell = exports.createDateCell = exports.createBorderedCell = exports.createStyledCell = exports.createRightBorder = exports.createLeftBorder = exports.createBottomBorder = exports.createTopBorder = exports.createAllBorders = exports.createBorder = exports.writeEquation = exports.skipCell = exports.EnvironmentType = exports.sampleData = exports.generateExcel = exports.VerticalAlignment = exports.HorizontalAlignment = exports.BorderStyle = exports.ICellType = void 0;
|
|
4
4
|
const generate_excel_1 = require("./generate-excel");
|
|
5
5
|
Object.defineProperty(exports, "generateExcel", { enumerable: true, get: function () { return generate_excel_1.generateExcel; } });
|
|
6
6
|
Object.defineProperty(exports, "EnvironmentType", { enumerable: true, get: function () { return generate_excel_1.EnvironmentType; } });
|
|
@@ -21,6 +21,10 @@ Object.defineProperty(exports, "createBackgroundCell", { enumerable: true, get:
|
|
|
21
21
|
Object.defineProperty(exports, "createForegroundCell", { enumerable: true, get: function () { return util_1.createForegroundCell; } });
|
|
22
22
|
Object.defineProperty(exports, "createColoredCell", { enumerable: true, get: function () { return util_1.createColoredCell; } });
|
|
23
23
|
Object.defineProperty(exports, "createBackgroundDateCell", { enumerable: true, get: function () { return util_1.createBackgroundDateCell; } });
|
|
24
|
+
Object.defineProperty(exports, "createHorizontallyAlignedCell", { enumerable: true, get: function () { return util_1.createHorizontallyAlignedCell; } });
|
|
25
|
+
Object.defineProperty(exports, "createVerticallyAlignedCell", { enumerable: true, get: function () { return util_1.createVerticallyAlignedCell; } });
|
|
26
|
+
Object.defineProperty(exports, "createAlignedCell", { enumerable: true, get: function () { return util_1.createAlignedCell; } });
|
|
27
|
+
Object.defineProperty(exports, "createCenteredCell", { enumerable: true, get: function () { return util_1.createCenteredCell; } });
|
|
24
28
|
var ICellType;
|
|
25
29
|
(function (ICellType) {
|
|
26
30
|
ICellType["string"] = "s";
|
|
@@ -41,6 +45,27 @@ var BorderStyle;
|
|
|
41
45
|
BorderStyle["dashed"] = "dashed";
|
|
42
46
|
})(BorderStyle || (BorderStyle = {}));
|
|
43
47
|
exports.BorderStyle = BorderStyle;
|
|
48
|
+
var HorizontalAlignment;
|
|
49
|
+
(function (HorizontalAlignment) {
|
|
50
|
+
HorizontalAlignment["general"] = "general";
|
|
51
|
+
HorizontalAlignment["left"] = "left";
|
|
52
|
+
HorizontalAlignment["center"] = "center";
|
|
53
|
+
HorizontalAlignment["right"] = "right";
|
|
54
|
+
HorizontalAlignment["fill"] = "fill";
|
|
55
|
+
HorizontalAlignment["justify"] = "justify";
|
|
56
|
+
HorizontalAlignment["centerContinuous"] = "centerContinuous";
|
|
57
|
+
HorizontalAlignment["distributed"] = "distributed";
|
|
58
|
+
})(HorizontalAlignment || (HorizontalAlignment = {}));
|
|
59
|
+
exports.HorizontalAlignment = HorizontalAlignment;
|
|
60
|
+
var VerticalAlignment;
|
|
61
|
+
(function (VerticalAlignment) {
|
|
62
|
+
VerticalAlignment["top"] = "top";
|
|
63
|
+
VerticalAlignment["center"] = "center";
|
|
64
|
+
VerticalAlignment["bottom"] = "bottom";
|
|
65
|
+
VerticalAlignment["justify"] = "justify";
|
|
66
|
+
VerticalAlignment["distributed"] = "distributed";
|
|
67
|
+
})(VerticalAlignment || (VerticalAlignment = {}));
|
|
68
|
+
exports.VerticalAlignment = VerticalAlignment;
|
|
44
69
|
const sampleData = [
|
|
45
70
|
{
|
|
46
71
|
title: 'Maifee1', content: [
|
|
@@ -151,6 +176,47 @@ const sampleData = [
|
|
|
151
176
|
42
|
|
152
177
|
]
|
|
153
178
|
]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
title: 'AlignmentDemo',
|
|
182
|
+
content: [
|
|
183
|
+
[
|
|
184
|
+
'Feature',
|
|
185
|
+
'Horizontal Alignment',
|
|
186
|
+
'Vertical Alignment',
|
|
187
|
+
'Both Alignments'
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
'Left Align',
|
|
191
|
+
(0, util_1.createHorizontallyAlignedCell)('Left Text', HorizontalAlignment.left),
|
|
192
|
+
(0, util_1.createVerticallyAlignedCell)('Top Text', VerticalAlignment.top),
|
|
193
|
+
(0, util_1.createAlignedCell)('Top-Left', HorizontalAlignment.left, VerticalAlignment.top)
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
'Center Align',
|
|
197
|
+
(0, util_1.createHorizontallyAlignedCell)('Center Text', HorizontalAlignment.center),
|
|
198
|
+
(0, util_1.createVerticallyAlignedCell)('Center Text', VerticalAlignment.center),
|
|
199
|
+
(0, util_1.createCenteredCell)('Full Center')
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
'Right Align',
|
|
203
|
+
(0, util_1.createHorizontallyAlignedCell)('Right Text', HorizontalAlignment.right),
|
|
204
|
+
(0, util_1.createVerticallyAlignedCell)('Bottom Text', VerticalAlignment.bottom),
|
|
205
|
+
(0, util_1.createAlignedCell)('Bottom-Right', HorizontalAlignment.right, VerticalAlignment.bottom)
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
'Complex Style',
|
|
209
|
+
(0, util_1.createStyledCell)('All Features', {
|
|
210
|
+
horizontalAlignment: HorizontalAlignment.center,
|
|
211
|
+
verticalAlignment: VerticalAlignment.center,
|
|
212
|
+
backgroundColor: '#CCFFCC',
|
|
213
|
+
foregroundColor: '#FF0000',
|
|
214
|
+
border: (0, util_1.createAllBorders)(BorderStyle.thick, '#000000')
|
|
215
|
+
}),
|
|
216
|
+
(0, util_1.createAlignedCell)(new Date(), HorizontalAlignment.right, VerticalAlignment.center),
|
|
217
|
+
(0, util_1.createCenteredCell)(42)
|
|
218
|
+
]
|
|
219
|
+
]
|
|
154
220
|
}
|
|
155
221
|
];
|
|
156
222
|
exports.sampleData = sampleData;
|
package/lib/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRows, IBorder, BorderStyle, ICellStyle, ICell } from ".";
|
|
1
|
+
import { IRows, IBorder, BorderStyle, ICellStyle, ICell, HorizontalAlignment, VerticalAlignment } from ".";
|
|
2
2
|
declare const indexToVbIndex: (index: number) => number;
|
|
3
3
|
declare const indexToVbRelationIndex: (index: number) => number;
|
|
4
4
|
declare const indexToRowIndex: (index: number) => string;
|
|
@@ -33,4 +33,8 @@ declare const createBackgroundCell: (value: string | number, backgroundColor: st
|
|
|
33
33
|
declare const createForegroundCell: (value: string | number, foregroundColor: string) => ICell;
|
|
34
34
|
declare const createColoredCell: (value: string | number, backgroundColor: string, foregroundColor: string) => ICell;
|
|
35
35
|
declare const createBackgroundDateCell: (date: Date, backgroundColor: string) => ICell;
|
|
36
|
-
|
|
36
|
+
declare const createHorizontallyAlignedCell: (value: string | number | Date, alignment: HorizontalAlignment) => ICell;
|
|
37
|
+
declare const createVerticallyAlignedCell: (value: string | number | Date, alignment: VerticalAlignment) => ICell;
|
|
38
|
+
declare const createAlignedCell: (value: string | number | Date, horizontal: HorizontalAlignment, vertical: VerticalAlignment) => ICell;
|
|
39
|
+
declare const createCenteredCell: (value: string | number | Date) => ICell;
|
|
40
|
+
export { indexToVbIndex, indexToVbRelationIndex, indexToRowIndex, rowColumnToVbPosition, calculateExtant, SkipCell, skipCell, Equation, writeEquation, createBorder, createAllBorders, createTopBorder, createBottomBorder, createLeftBorder, createRightBorder, getBorderKey, getStyleKey, createStyledCell, createBorderedCell, dateToExcelSerial, createDateCell, createBorderedDateCell, createBackgroundCell, createForegroundCell, createColoredCell, createBackgroundDateCell, createHorizontallyAlignedCell, createVerticallyAlignedCell, createAlignedCell, createCenteredCell };
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createBackgroundDateCell = exports.createColoredCell = exports.createForegroundCell = exports.createBackgroundCell = exports.createBorderedDateCell = exports.createDateCell = exports.dateToExcelSerial = exports.createBorderedCell = exports.createStyledCell = exports.getStyleKey = exports.getBorderKey = exports.createRightBorder = exports.createLeftBorder = exports.createBottomBorder = exports.createTopBorder = exports.createAllBorders = exports.createBorder = exports.writeEquation = exports.Equation = exports.skipCell = exports.SkipCell = exports.calculateExtant = exports.rowColumnToVbPosition = exports.indexToRowIndex = exports.indexToVbRelationIndex = exports.indexToVbIndex = void 0;
|
|
3
|
+
exports.createCenteredCell = exports.createAlignedCell = exports.createVerticallyAlignedCell = exports.createHorizontallyAlignedCell = exports.createBackgroundDateCell = exports.createColoredCell = exports.createForegroundCell = exports.createBackgroundCell = exports.createBorderedDateCell = exports.createDateCell = exports.dateToExcelSerial = exports.createBorderedCell = exports.createStyledCell = exports.getStyleKey = exports.getBorderKey = exports.createRightBorder = exports.createLeftBorder = exports.createBottomBorder = exports.createTopBorder = exports.createAllBorders = exports.createBorder = exports.writeEquation = exports.Equation = exports.skipCell = exports.SkipCell = exports.calculateExtant = exports.rowColumnToVbPosition = exports.indexToRowIndex = exports.indexToVbRelationIndex = exports.indexToVbIndex = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const indexToVbIndex = (index) => index + 1;
|
|
6
6
|
exports.indexToVbIndex = indexToVbIndex;
|
|
@@ -88,7 +88,9 @@ const getStyleKey = (style) => {
|
|
|
88
88
|
const parts = [
|
|
89
89
|
getBorderKey(style.border),
|
|
90
90
|
style.backgroundColor || "no-bg",
|
|
91
|
-
style.foregroundColor || "no-fg"
|
|
91
|
+
style.foregroundColor || "no-fg",
|
|
92
|
+
style.horizontalAlignment || "no-halign",
|
|
93
|
+
style.verticalAlignment || "no-valign"
|
|
92
94
|
];
|
|
93
95
|
return parts.join("|");
|
|
94
96
|
};
|
|
@@ -149,3 +151,34 @@ const createBackgroundDateCell = (date, backgroundColor) => {
|
|
|
149
151
|
return createDateCell(date, { backgroundColor });
|
|
150
152
|
};
|
|
151
153
|
exports.createBackgroundDateCell = createBackgroundDateCell;
|
|
154
|
+
const createHorizontallyAlignedCell = (value, alignment) => {
|
|
155
|
+
if (value instanceof Date) {
|
|
156
|
+
return createDateCell(value, { horizontalAlignment: alignment });
|
|
157
|
+
}
|
|
158
|
+
return createStyledCell(value, { horizontalAlignment: alignment });
|
|
159
|
+
};
|
|
160
|
+
exports.createHorizontallyAlignedCell = createHorizontallyAlignedCell;
|
|
161
|
+
const createVerticallyAlignedCell = (value, alignment) => {
|
|
162
|
+
if (value instanceof Date) {
|
|
163
|
+
return createDateCell(value, { verticalAlignment: alignment });
|
|
164
|
+
}
|
|
165
|
+
return createStyledCell(value, { verticalAlignment: alignment });
|
|
166
|
+
};
|
|
167
|
+
exports.createVerticallyAlignedCell = createVerticallyAlignedCell;
|
|
168
|
+
const createAlignedCell = (value, horizontal, vertical) => {
|
|
169
|
+
if (value instanceof Date) {
|
|
170
|
+
return createDateCell(value, {
|
|
171
|
+
horizontalAlignment: horizontal,
|
|
172
|
+
verticalAlignment: vertical
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return createStyledCell(value, {
|
|
176
|
+
horizontalAlignment: horizontal,
|
|
177
|
+
verticalAlignment: vertical
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
exports.createAlignedCell = createAlignedCell;
|
|
181
|
+
const createCenteredCell = (value) => {
|
|
182
|
+
return createAlignedCell(value, _1.HorizontalAlignment.center, _1.VerticalAlignment.center);
|
|
183
|
+
};
|
|
184
|
+
exports.createCenteredCell = createCenteredCell;
|
package/lib/xl/styles.xml.js
CHANGED
|
@@ -59,6 +59,20 @@ const generateFillXml = (color) => {
|
|
|
59
59
|
</patternFill>
|
|
60
60
|
</fill>`;
|
|
61
61
|
};
|
|
62
|
+
const generateAlignmentXml = (style) => {
|
|
63
|
+
const hasAlignment = style.horizontalAlignment || style.verticalAlignment;
|
|
64
|
+
if (!hasAlignment) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
let alignmentAttrs = '';
|
|
68
|
+
if (style.horizontalAlignment) {
|
|
69
|
+
alignmentAttrs += ` horizontal="${style.horizontalAlignment}"`;
|
|
70
|
+
}
|
|
71
|
+
if (style.verticalAlignment) {
|
|
72
|
+
alignmentAttrs += ` vertical="${style.verticalAlignment}"`;
|
|
73
|
+
}
|
|
74
|
+
return `<alignment${alignmentAttrs} />`;
|
|
75
|
+
};
|
|
62
76
|
const generateStyleXml = (styleMap, hasDateCells = false) => {
|
|
63
77
|
const styles = Array.from(styleMap.values());
|
|
64
78
|
const styleCount = styles.length;
|
|
@@ -98,14 +112,18 @@ const generateStyleXml = (styleMap, hasDateCells = false) => {
|
|
|
98
112
|
const borderIndex = Array.from(uniqueBorders.keys()).indexOf(JSON.stringify(style.border || {}));
|
|
99
113
|
const fontIndex = Array.from(uniqueFonts.keys()).indexOf(style.foregroundColor || "default");
|
|
100
114
|
const fillIndex = Array.from(uniqueFills.keys()).indexOf(style.backgroundColor || "none");
|
|
101
|
-
|
|
115
|
+
const alignmentXml = generateAlignmentXml(style);
|
|
116
|
+
const applyAlignment = style.horizontalAlignment || style.verticalAlignment ? ' applyAlignment="1"' : '';
|
|
117
|
+
return `<xf numFmtId="0" fontId="${fontIndex}" fillId="${fillIndex}" borderId="${borderIndex}" xfId="0"${applyAlignment}>${alignmentXml}</xf>`;
|
|
102
118
|
}).join('\n ');
|
|
103
119
|
cellXfsXml += '\n ';
|
|
104
120
|
cellXfsXml += styles.map((style, index) => {
|
|
105
121
|
const borderIndex = Array.from(uniqueBorders.keys()).indexOf(JSON.stringify(style.border || {}));
|
|
106
122
|
const fontIndex = Array.from(uniqueFonts.keys()).indexOf(style.foregroundColor || "default");
|
|
107
123
|
const fillIndex = Array.from(uniqueFills.keys()).indexOf(style.backgroundColor || "none");
|
|
108
|
-
|
|
124
|
+
const alignmentXml = generateAlignmentXml(style);
|
|
125
|
+
const applyAlignment = style.horizontalAlignment || style.verticalAlignment ? ' applyAlignment="1"' : '';
|
|
126
|
+
return `<xf numFmtId="164" fontId="${fontIndex}" fillId="${fillIndex}" borderId="${borderIndex}" xfId="0"${applyAlignment}>${alignmentXml}</xf>`;
|
|
109
127
|
}).join('\n ');
|
|
110
128
|
cellXfsCount = styleCount * 2;
|
|
111
129
|
}
|
|
@@ -114,7 +132,9 @@ const generateStyleXml = (styleMap, hasDateCells = false) => {
|
|
|
114
132
|
const borderIndex = Array.from(uniqueBorders.keys()).indexOf(JSON.stringify(style.border || {}));
|
|
115
133
|
const fontIndex = Array.from(uniqueFonts.keys()).indexOf(style.foregroundColor || "default");
|
|
116
134
|
const fillIndex = Array.from(uniqueFills.keys()).indexOf(style.backgroundColor || "none");
|
|
117
|
-
|
|
135
|
+
const alignmentXml = generateAlignmentXml(style);
|
|
136
|
+
const applyAlignment = style.horizontalAlignment || style.verticalAlignment ? ' applyAlignment="1"' : '';
|
|
137
|
+
return `<xf numFmtId="0" fontId="${fontIndex}" fillId="${fillIndex}" borderId="${borderIndex}" xfId="0"${applyAlignment}>${alignmentXml}</xf>`;
|
|
118
138
|
}).join('\n ');
|
|
119
139
|
}
|
|
120
140
|
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|