abstract-sheet 0.0.3 → 0.0.4
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/lib/abstract-sheet/abstract-sheet-xsd.d.ts +1 -1
- package/lib/abstract-sheet/abstract-sheet-xsd.d.ts.map +1 -1
- package/lib/abstract-sheet/abstract-sheet-xsd.js +41 -45
- package/lib/abstract-sheet/abstract-sheet-xsd.js.map +1 -1
- package/lib/abstract-sheet/abstract-sheet.d.ts +22 -9
- package/lib/abstract-sheet/abstract-sheet.d.ts.map +1 -1
- package/lib/abstract-sheet/abstract-sheet.js.map +1 -1
- package/lib/abstract-sheet-exporters/_style.d.ts +3 -0
- package/lib/abstract-sheet-exporters/_style.d.ts.map +1 -0
- package/lib/abstract-sheet-exporters/_style.js +113 -0
- package/lib/abstract-sheet-exporters/_style.js.map +1 -0
- package/lib/abstract-sheet-exporters/_xlsx-sheet.d.ts +2 -3
- package/lib/abstract-sheet-exporters/_xlsx-sheet.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/_xlsx-sheet.js +14 -116
- package/lib/abstract-sheet-exporters/_xlsx-sheet.js.map +1 -1
- package/lib/abstract-sheet-exporters/csv.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/csv.js +2 -1
- package/lib/abstract-sheet-exporters/csv.js.map +1 -1
- package/lib/abstract-sheet-exporters/index.d.ts +1 -0
- package/lib/abstract-sheet-exporters/index.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/index.js +1 -0
- package/lib/abstract-sheet-exporters/index.js.map +1 -1
- package/lib/abstract-sheet-exporters/react.d.ts +5 -0
- package/lib/abstract-sheet-exporters/react.d.ts.map +1 -0
- package/lib/abstract-sheet-exporters/react.js +135 -0
- package/lib/abstract-sheet-exporters/react.js.map +1 -0
- package/lib/abstract-sheet-exporters/xlsx.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/xlsx.js +2 -1
- package/lib/abstract-sheet-exporters/xlsx.js.map +1 -1
- package/lib/abstract-sheet-xml/abstract-sheet-xml.d.ts +3 -1
- package/lib/abstract-sheet-xml/abstract-sheet-xml.d.ts.map +1 -1
- package/lib/abstract-sheet-xml/abstract-sheet-xml.js +33 -22
- package/lib/abstract-sheet-xml/abstract-sheet-xml.js.map +1 -1
- package/package.json +6 -2
- package/src/abstract-sheet/abstract-sheet-xsd.ts +41 -45
- package/src/abstract-sheet/abstract-sheet-xsd.xml +41 -45
- package/src/abstract-sheet/abstract-sheet.ts +10 -12
- package/src/abstract-sheet-exporters/_style.ts +113 -0
- package/src/abstract-sheet-exporters/_xlsx-sheet.ts +19 -121
- package/src/abstract-sheet-exporters/csv.ts +2 -1
- package/src/abstract-sheet-exporters/index.ts +1 -0
- package/src/abstract-sheet-exporters/react.tsx +185 -0
- package/src/abstract-sheet-exporters/xlsx.ts +2 -1
- package/src/abstract-sheet-xml/abstract-sheet-xml.ts +31 -22
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
<?xml version="1.
|
|
1
|
+
<?xml version="1.1" encoding="UTF-8"?>
|
|
2
2
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
3
3
|
|
|
4
4
|
<xs:element name="AbstractSheet">
|
|
5
5
|
<xs:complexType>
|
|
6
6
|
<xs:sequence>
|
|
7
|
-
<xs:element name="Styles" type="Styles" minOccurs="0" />
|
|
8
|
-
<xs:element name="
|
|
7
|
+
<xs:element name="Styles" type="Styles" minOccurs="0" maxOccurs="1" />
|
|
8
|
+
<xs:element name="Sheet" type="Sheet" />
|
|
9
9
|
</xs:sequence>
|
|
10
10
|
</xs:complexType>
|
|
11
11
|
</xs:element>
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
<xs:complexType name="Sheets">
|
|
15
|
-
<xs:sequence>
|
|
16
|
-
<xs:element name="Sheet" type="Sheet" minOccurs="0" />
|
|
17
|
-
</xs:sequence>
|
|
18
|
-
</xs:complexType>
|
|
19
|
-
|
|
20
13
|
<xs:complexType name="Sheet">
|
|
21
14
|
<xs:sequence>
|
|
22
|
-
<xs:element name="
|
|
15
|
+
<xs:element name="Cells" type="Cells" />
|
|
23
16
|
<xs:element name="RowInfos" type="RowInfos" minOccurs="0" maxOccurs="1" />
|
|
24
17
|
<xs:element name="ColInfos" type="ColInfos" minOccurs="0" maxOccurs="1" />
|
|
25
18
|
</xs:sequence>
|
|
26
19
|
<xs:attribute name="name" type="xs:string" use="required" />
|
|
20
|
+
<xs:attribute name="direction">
|
|
21
|
+
<xs:simpleType>
|
|
22
|
+
<xs:restriction base="xs:string">
|
|
23
|
+
<xs:enumeration value="row" />
|
|
24
|
+
<xs:enumeration value="col" />
|
|
25
|
+
</xs:restriction>
|
|
26
|
+
</xs:simpleType>
|
|
27
|
+
</xs:attribute>
|
|
27
28
|
</xs:complexType>
|
|
28
29
|
|
|
29
30
|
<xs:complexType name="ColInfos">
|
|
@@ -48,43 +49,20 @@
|
|
|
48
49
|
<xs:attribute name="heightPixels" type="xs:integer" />
|
|
49
50
|
</xs:complexType>
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
<xs:complexType name="Rows">
|
|
53
|
-
<xs:sequence>
|
|
54
|
-
<xs:element name="Row" type="Row" />
|
|
55
|
-
</xs:sequence>
|
|
56
|
-
</xs:complexType>
|
|
57
|
-
|
|
58
|
-
<xs:complexType name="Row">
|
|
52
|
+
<xs:complexType name="Cells">
|
|
59
53
|
<xs:sequence>
|
|
60
54
|
<xs:element name="Cell" type="Cell" />
|
|
61
55
|
</xs:sequence>
|
|
62
56
|
</xs:complexType>
|
|
63
57
|
|
|
64
58
|
<xs:complexType name="Cell">
|
|
65
|
-
<xs:attribute name="
|
|
59
|
+
<xs:attribute name="number" type="xs:string" use="optional" />
|
|
60
|
+
<xs:attribute name="text" type="xs:string" use="optional" />
|
|
61
|
+
<xs:attribute name="bool" type="xs:string" use="optional" />
|
|
62
|
+
<xs:attribute name="date" type="xs:string" use="optional" />
|
|
66
63
|
<xs:attribute name="styles" type="xs:string" />
|
|
67
|
-
<xs:attribute name="type">
|
|
68
|
-
<xs:simpleType>
|
|
69
|
-
<xs:restriction base="xs:string">
|
|
70
|
-
<xs:enumeration value="string" />
|
|
71
|
-
<xs:enumeration value="number" />
|
|
72
|
-
</xs:restriction>
|
|
73
|
-
</xs:simpleType>
|
|
74
|
-
</xs:attribute>
|
|
75
64
|
</xs:complexType>
|
|
76
65
|
|
|
77
|
-
<xs:simpleType name="NumberOrString">
|
|
78
|
-
<xs:union>
|
|
79
|
-
<xs:simpleType>
|
|
80
|
-
<xs:restriction base="xs:double" />
|
|
81
|
-
</xs:simpleType>
|
|
82
|
-
<xs:simpleType>
|
|
83
|
-
<xs:restriction base="xs:string" />
|
|
84
|
-
</xs:simpleType>
|
|
85
|
-
</xs:union>
|
|
86
|
-
</xs:simpleType>
|
|
87
|
-
|
|
88
66
|
<xs:complexType name="Styles">
|
|
89
67
|
<xs:sequence>
|
|
90
68
|
<xs:element name="Style" minOccurs="0" maxOccurs="unbounded" />
|
|
@@ -112,9 +90,9 @@
|
|
|
112
90
|
</xs:simpleType>
|
|
113
91
|
</xs:attribute>
|
|
114
92
|
<xs:attribute name="wrapText" type="xs:boolean" />
|
|
115
|
-
<xs:attribute name="textRotation" type="xs:
|
|
116
|
-
<xs:attribute name="borderStyle" type="
|
|
117
|
-
<xs:attribute name="borderColor" type="
|
|
93
|
+
<xs:attribute name="textRotation" type="xs:double" />
|
|
94
|
+
<xs:attribute name="borderStyle" type="BorderStyle" />
|
|
95
|
+
<xs:attribute name="borderColor" type="BorderColor" />
|
|
118
96
|
<xs:attribute name="fillType">
|
|
119
97
|
<xs:simpleType>
|
|
120
98
|
<xs:restriction base="xs:string">
|
|
@@ -123,10 +101,10 @@
|
|
|
123
101
|
</xs:restriction>
|
|
124
102
|
</xs:simpleType>
|
|
125
103
|
</xs:attribute>
|
|
126
|
-
<xs:attribute name="foreground" type="
|
|
127
|
-
<xs:attribute name="background" type="
|
|
104
|
+
<xs:attribute name="foreground" type="HexColorWithOpacity" />
|
|
105
|
+
<xs:attribute name="background" type="HexColorWithOpacity" />
|
|
128
106
|
<xs:attribute name="bold" type="xs:boolean" />
|
|
129
|
-
<xs:attribute name="color" type="
|
|
107
|
+
<xs:attribute name="color" type="HexColorWithOpacity" />
|
|
130
108
|
<xs:attribute name="italic" type="xs:boolean" />
|
|
131
109
|
<xs:attribute name="font" type="xs:string" />
|
|
132
110
|
<xs:attribute name="strike" type="xs:boolean" />
|
|
@@ -143,4 +121,22 @@
|
|
|
143
121
|
<xs:attribute name="numberFormat" type="xs:string" />
|
|
144
122
|
</xs:complexType>
|
|
145
123
|
|
|
124
|
+
<xs:simpleType name="HexColorWithOpacity">
|
|
125
|
+
<xs:restriction base="xs:string">
|
|
126
|
+
<xs:pattern value="#[0-9a-fA-F]{8}" />
|
|
127
|
+
</xs:restriction>
|
|
128
|
+
</xs:simpleType>
|
|
129
|
+
|
|
130
|
+
<xs:simpleType name="BorderColor">
|
|
131
|
+
<xs:restriction base="xs:string">
|
|
132
|
+
<xs:pattern value="^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})(\s#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})){0,3}$" />
|
|
133
|
+
</xs:restriction>
|
|
134
|
+
</xs:simpleType>
|
|
135
|
+
|
|
136
|
+
<xs:simpleType name="BorderStyle">
|
|
137
|
+
<xs:restriction base="xs:string">
|
|
138
|
+
<xs:pattern value="^(dashDotDot|dashDot|dashed|dotted|hair|mediumDashDotDot|mediumDashDot|mediumDashed|medium|slantDashDot|thick|thin)(\s(dashDotDot|dashDot|dashed|dotted|hair|mediumDashDotDot|mediumDashDot|mediumDashed|medium|slantDashDot|thick|thin)){0,3}$" />
|
|
139
|
+
</xs:restriction>
|
|
140
|
+
</xs:simpleType>
|
|
141
|
+
|
|
146
142
|
</xs:schema>
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export type AbstractSheet = {
|
|
2
|
-
readonly sheets:
|
|
2
|
+
readonly sheets: ReadonlyArray<Sheet>;
|
|
3
3
|
readonly styles?: Styles;
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
-
export type Sheets = ReadonlyArray<Sheet>;
|
|
7
|
-
|
|
8
6
|
export type Sheet = {
|
|
9
7
|
readonly name: string;
|
|
10
|
-
readonly
|
|
8
|
+
readonly cells: ReadonlyArray<Cells>;
|
|
11
9
|
readonly colInfo?: ColInfos;
|
|
12
10
|
readonly rowInfo?: RowInfos;
|
|
11
|
+
readonly direction?: "row" | "col";
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
export type ColInfos = ReadonlyArray<ColInfo>;
|
|
@@ -20,17 +19,16 @@ export type RowInfos = ReadonlyArray<RowInfo>;
|
|
|
20
19
|
|
|
21
20
|
export type RowInfo = { readonly hidden?: boolean; readonly heightPixels?: number };
|
|
22
21
|
|
|
23
|
-
export type
|
|
22
|
+
export type Cells = ReadonlyArray<Cell>;
|
|
24
23
|
|
|
25
|
-
export type
|
|
24
|
+
export type Cell = (NumberCell | TextCell | BoolCell | DateCell) & { readonly styles?: ReadonlyArray<string> };
|
|
26
25
|
|
|
27
|
-
export type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
26
|
+
export type NumberCell = { readonly type: "number"; readonly value: string | number | boolean | Date };
|
|
27
|
+
export type TextCell = { readonly type: "string"; readonly value: string | number | boolean | Date };
|
|
28
|
+
export type BoolCell = { readonly type: "boolean"; readonly value: string | number | boolean | Date };
|
|
29
|
+
export type DateCell = { readonly type: "date"; readonly value: string | number | boolean | Date };
|
|
32
30
|
|
|
33
|
-
export type CellType = "
|
|
31
|
+
export type CellType = Cell["type"];
|
|
34
32
|
|
|
35
33
|
export type Styles = ReadonlyArray<Style>;
|
|
36
34
|
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Style } from "../abstract-sheet/abstract-sheet";
|
|
2
|
+
|
|
3
|
+
export function createStyle(style: Style): any {
|
|
4
|
+
let s: any = {};
|
|
5
|
+
if (style.vertical || style.horizontal || style.wrapText !== undefined || style.textRotation !== undefined) {
|
|
6
|
+
s.alignment = {};
|
|
7
|
+
if (style.vertical) {
|
|
8
|
+
s.alignment.vertical = style.vertical;
|
|
9
|
+
}
|
|
10
|
+
if (style.horizontal) {
|
|
11
|
+
s.alignment.horizontal = style.horizontal;
|
|
12
|
+
}
|
|
13
|
+
if (style.wrapText !== undefined) {
|
|
14
|
+
s.alignment.wrapText = style.wrapText;
|
|
15
|
+
}
|
|
16
|
+
if (style.textRotation !== undefined) {
|
|
17
|
+
s.alignment.textRotation = style.textRotation;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (style.fillType || style.foreground || style.background) {
|
|
21
|
+
s.fill = {};
|
|
22
|
+
if (style.fillType) {
|
|
23
|
+
s.fill.patternType = style.fillType;
|
|
24
|
+
}
|
|
25
|
+
if (style.foreground) {
|
|
26
|
+
s.fill.fgColor = { rgb: style.foreground.slice(1) };
|
|
27
|
+
}
|
|
28
|
+
if (style.background) {
|
|
29
|
+
s.fill.bgColor = { rgb: style.background.slice(1) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (style.borderStyle || style.borderColor) {
|
|
34
|
+
s.border = {};
|
|
35
|
+
if (style.borderStyle?.top || style.borderColor?.top) {
|
|
36
|
+
s.border.top = {};
|
|
37
|
+
}
|
|
38
|
+
if (style.borderStyle?.top) {
|
|
39
|
+
s.border.top.style = style.borderStyle.top;
|
|
40
|
+
}
|
|
41
|
+
if (style.borderColor?.top) {
|
|
42
|
+
s.border.top.color = { rgb: style.borderColor.top.slice(1) };
|
|
43
|
+
}
|
|
44
|
+
if (style.borderStyle?.right || style.borderColor?.right) {
|
|
45
|
+
s.border.right = {};
|
|
46
|
+
}
|
|
47
|
+
if (style.borderStyle?.right) {
|
|
48
|
+
s.border.right.style = style.borderStyle.right;
|
|
49
|
+
}
|
|
50
|
+
if (style.borderColor?.right) {
|
|
51
|
+
s.border.right.color = { rgb: style.borderColor.right.slice(1) };
|
|
52
|
+
}
|
|
53
|
+
if (style.borderStyle?.bottom || style.borderColor?.bottom) {
|
|
54
|
+
s.border.bottom = {};
|
|
55
|
+
}
|
|
56
|
+
if (style.borderStyle?.bottom) {
|
|
57
|
+
s.border.bottom.style = style.borderStyle.bottom;
|
|
58
|
+
}
|
|
59
|
+
if (style.borderColor?.bottom) {
|
|
60
|
+
s.border.bottom.color = { rgb: style.borderColor.bottom.slice(1) };
|
|
61
|
+
}
|
|
62
|
+
if (style.borderStyle?.left || style.borderColor?.left) {
|
|
63
|
+
s.border.left = {};
|
|
64
|
+
}
|
|
65
|
+
if (style.borderStyle?.left) {
|
|
66
|
+
s.border.left.style = style.borderStyle.left;
|
|
67
|
+
}
|
|
68
|
+
if (style.borderColor?.left) {
|
|
69
|
+
s.border.left.color = { rgb: style.borderColor.left.slice(1) };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
style.bold !== undefined ||
|
|
75
|
+
style.color ||
|
|
76
|
+
style.italic !== undefined ||
|
|
77
|
+
style.font ||
|
|
78
|
+
style.strike !== undefined ||
|
|
79
|
+
style.size !== undefined ||
|
|
80
|
+
style.underline !== undefined ||
|
|
81
|
+
style.script
|
|
82
|
+
) {
|
|
83
|
+
s.font = {};
|
|
84
|
+
if (style.bold !== undefined) {
|
|
85
|
+
s.font.bold = style.bold;
|
|
86
|
+
}
|
|
87
|
+
if (style.color) {
|
|
88
|
+
s.font.color = { rgb: style.color.slice(1) };
|
|
89
|
+
}
|
|
90
|
+
if (style.italic !== undefined) {
|
|
91
|
+
s.font.italic = style.italic;
|
|
92
|
+
}
|
|
93
|
+
if (style.font) {
|
|
94
|
+
s.font.name = style.font;
|
|
95
|
+
}
|
|
96
|
+
if (style.strike !== undefined) {
|
|
97
|
+
s.font.strike = style.strike;
|
|
98
|
+
}
|
|
99
|
+
if (style.size !== undefined) {
|
|
100
|
+
s.font.sz = style.size;
|
|
101
|
+
}
|
|
102
|
+
if (style.underline !== undefined) {
|
|
103
|
+
s.font.underline = style.underline;
|
|
104
|
+
}
|
|
105
|
+
if (style.script !== undefined) {
|
|
106
|
+
s.font.vertAlign = style.script;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (style.numberFormat !== undefined) {
|
|
110
|
+
s.font.numFmt = style.numberFormat;
|
|
111
|
+
}
|
|
112
|
+
return s;
|
|
113
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as XLSX from "xlsx-js-style";
|
|
2
|
-
import {
|
|
2
|
+
import { CellType, Sheet } from "../abstract-sheet/abstract-sheet";
|
|
3
3
|
|
|
4
|
-
export function xlsxWorkSheet(
|
|
4
|
+
export function xlsxWorkSheet(sheet: Sheet, styles: Record<string, any>): XLSX.WorkSheet {
|
|
5
5
|
let colMax = -1;
|
|
6
6
|
const cells: Record<string, XLSX.CellObject> = {};
|
|
7
|
-
for (let ri = 0; ri <
|
|
8
|
-
const r =
|
|
7
|
+
for (let ri = 0; ri < sheet.cells.length; ri++) {
|
|
8
|
+
const r = sheet.cells[ri]!;
|
|
9
9
|
colMax = Math.max(r.length, colMax);
|
|
10
10
|
for (let ci = 0; ci < r.length; ci++) {
|
|
11
11
|
const c = r[ci]!;
|
|
@@ -15,23 +15,33 @@ export function xlsxWorkSheet(s: Sheet, styles: Record<string, any>): XLSX.WorkS
|
|
|
15
15
|
s = { ...s!, ...styles[style] };
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
const key =
|
|
19
|
+
sheet.direction === "col" ? `${XLSX.utils.encode_col(ri)}${ci + 1}` : `${XLSX.utils.encode_col(ci)}${ri + 1}`;
|
|
20
|
+
cells[key] = { v: c.value, t: cellObject(c.type), s };
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
return {
|
|
23
25
|
"!type": "sheet",
|
|
24
|
-
"!ref": `A1:${
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
"!ref": `A1:${
|
|
27
|
+
sheet.direction === "col"
|
|
28
|
+
? `${XLSX.utils.encode_col(sheet.cells.length)}${colMax}`
|
|
29
|
+
: `${XLSX.utils.encode_col(colMax)}${sheet.cells.length}`
|
|
30
|
+
}`,
|
|
31
|
+
"!cols": sheet.colInfo?.map((i): XLSX.ColInfo => ({ wpx: i.widthPixels ?? 64, hidden: i.hidden })),
|
|
32
|
+
"!rows": sheet.rowInfo?.map((i): XLSX.RowInfo => ({ hpx: i.heightPixels ?? 15, hidden: i.hidden })),
|
|
27
33
|
...cells,
|
|
28
34
|
};
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
const
|
|
37
|
+
const cellObject = (colType: CellType | undefined): XLSX.CellObject["t"] => {
|
|
32
38
|
switch (colType) {
|
|
33
39
|
case "number":
|
|
34
40
|
return "n";
|
|
41
|
+
case "boolean":
|
|
42
|
+
return "b";
|
|
43
|
+
case "date":
|
|
44
|
+
return "d";
|
|
35
45
|
case undefined:
|
|
36
46
|
case "string":
|
|
37
47
|
return "s";
|
|
@@ -42,115 +52,3 @@ const columnType = (colType: CellType | undefined): XLSX.CellObject["t"] => {
|
|
|
42
52
|
};
|
|
43
53
|
|
|
44
54
|
const exhaustiveCheck = (check: never): never => check;
|
|
45
|
-
|
|
46
|
-
export function createStyle(style: Style): any {
|
|
47
|
-
let s: any = {};
|
|
48
|
-
if (style.vertical || style.horizontal || style.wrapText !== undefined || style.textRotation !== undefined) {
|
|
49
|
-
s.alignment = {};
|
|
50
|
-
if (style.vertical) {
|
|
51
|
-
s.alignment.vertical = style.vertical;
|
|
52
|
-
}
|
|
53
|
-
if (style.horizontal) {
|
|
54
|
-
s.alignment.horizontal = style.horizontal;
|
|
55
|
-
}
|
|
56
|
-
if (style.wrapText !== undefined) {
|
|
57
|
-
s.alignment.wrapText = style.wrapText;
|
|
58
|
-
}
|
|
59
|
-
if (style.textRotation !== undefined) {
|
|
60
|
-
s.alignment.textRotation = style.textRotation;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (style.fillType || style.foreground || style.background) {
|
|
64
|
-
s.fill = {};
|
|
65
|
-
if (style.fillType) {
|
|
66
|
-
s.fill.patternType = style.fillType;
|
|
67
|
-
}
|
|
68
|
-
if (style.foreground) {
|
|
69
|
-
s.fill.fgColor = { rgb: style.foreground };
|
|
70
|
-
}
|
|
71
|
-
if (style.background) {
|
|
72
|
-
s.fill.bgColor = { rgb: style.background };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (style.borderStyle || style.borderColor) {
|
|
77
|
-
s.border = {};
|
|
78
|
-
if (style.borderStyle?.top || style.borderColor?.top) {
|
|
79
|
-
s.border.top = {};
|
|
80
|
-
}
|
|
81
|
-
if (style.borderStyle?.top) {
|
|
82
|
-
s.border.top.style = style.borderStyle.top;
|
|
83
|
-
}
|
|
84
|
-
if (style.borderColor?.top) {
|
|
85
|
-
s.border.top.color = { rgb: style.borderColor.top };
|
|
86
|
-
}
|
|
87
|
-
if (style.borderStyle?.right || style.borderColor?.right) {
|
|
88
|
-
s.border.right = {};
|
|
89
|
-
}
|
|
90
|
-
if (style.borderStyle?.right) {
|
|
91
|
-
s.border.right.style = style.borderStyle.right;
|
|
92
|
-
}
|
|
93
|
-
if (style.borderColor?.right) {
|
|
94
|
-
s.border.right.color = { rgb: style.borderColor.right };
|
|
95
|
-
}
|
|
96
|
-
if (style.borderStyle?.bottom || style.borderColor?.bottom) {
|
|
97
|
-
s.border.bottom = {};
|
|
98
|
-
}
|
|
99
|
-
if (style.borderStyle?.bottom) {
|
|
100
|
-
s.border.bottom.style = style.borderStyle.bottom;
|
|
101
|
-
}
|
|
102
|
-
if (style.borderColor?.bottom) {
|
|
103
|
-
s.border.bottom.color = { rgb: style.borderColor.bottom };
|
|
104
|
-
}
|
|
105
|
-
if (style.borderStyle?.left || style.borderColor?.left) {
|
|
106
|
-
s.border.left = {};
|
|
107
|
-
}
|
|
108
|
-
if (style.borderStyle?.left) {
|
|
109
|
-
s.border.left.style = style.borderStyle.left;
|
|
110
|
-
}
|
|
111
|
-
if (style.borderColor?.left) {
|
|
112
|
-
s.border.left.color = { rgb: style.borderColor.left };
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
style.bold !== undefined ||
|
|
118
|
-
style.color ||
|
|
119
|
-
style.italic !== undefined ||
|
|
120
|
-
style.font ||
|
|
121
|
-
style.strike !== undefined ||
|
|
122
|
-
style.size !== undefined ||
|
|
123
|
-
style.underline !== undefined ||
|
|
124
|
-
style.script
|
|
125
|
-
) {
|
|
126
|
-
s.font = {};
|
|
127
|
-
if (style.bold !== undefined) {
|
|
128
|
-
s.font.bold = style.bold;
|
|
129
|
-
}
|
|
130
|
-
if (style.color) {
|
|
131
|
-
s.font.color = { rgb: style.color };
|
|
132
|
-
}
|
|
133
|
-
if (style.italic !== undefined) {
|
|
134
|
-
s.font.italic = style.italic;
|
|
135
|
-
}
|
|
136
|
-
if (style.font) {
|
|
137
|
-
s.font.name = style.font;
|
|
138
|
-
}
|
|
139
|
-
if (style.strike !== undefined) {
|
|
140
|
-
s.font.strike = style.strike;
|
|
141
|
-
}
|
|
142
|
-
if (style.size !== undefined) {
|
|
143
|
-
s.font.sz = style.size;
|
|
144
|
-
}
|
|
145
|
-
if (style.underline !== undefined) {
|
|
146
|
-
s.font.underline = style.underline;
|
|
147
|
-
}
|
|
148
|
-
if (style.script !== undefined) {
|
|
149
|
-
s.font.vertAlign = style.script;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (style.numberFormat !== undefined) {
|
|
153
|
-
s.font.numFmt = style.numberFormat;
|
|
154
|
-
}
|
|
155
|
-
return s;
|
|
156
|
-
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as XLSX from "xlsx-js-style";
|
|
2
2
|
import { AbstractSheet } from "../abstract-sheet/abstract-sheet";
|
|
3
|
-
import {
|
|
3
|
+
import { xlsxWorkSheet } from "./_xlsx-sheet";
|
|
4
|
+
import { createStyle } from "./_style";
|
|
4
5
|
|
|
5
6
|
export type CsvFile = { readonly name: string; readonly csv: string };
|
|
6
7
|
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AbstractSheet, BorderStyle, Style } from "../abstract-sheet/abstract-sheet";
|
|
3
|
+
|
|
4
|
+
export function toReact({ abstractSheet }: { readonly abstractSheet: AbstractSheet }): JSX.Element {
|
|
5
|
+
const styles = React.useMemo(
|
|
6
|
+
() => Object.fromEntries(abstractSheet.styles?.map((s) => [s.name, s]) ?? []),
|
|
7
|
+
[abstractSheet.styles]
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div className="abstract-sheet">
|
|
12
|
+
{abstractSheet.sheets.map((s, si) => {
|
|
13
|
+
const maxCols = s.cells.reduce((a, c) => Math.max(a, c.length), 0);
|
|
14
|
+
const colArray = Array.from({ length: maxCols }, (_, i) => i);
|
|
15
|
+
return (
|
|
16
|
+
<div
|
|
17
|
+
className={`sheet sheet-${si} sheet-${s.name}`}
|
|
18
|
+
key={s.name}
|
|
19
|
+
style={{
|
|
20
|
+
display: "grid",
|
|
21
|
+
width: "max-content",
|
|
22
|
+
height: "max-content",
|
|
23
|
+
border: "1px solid rgb(200,200,200)",
|
|
24
|
+
gridTemplateRows: `${(s.direction === "col" ? colArray : s.cells)
|
|
25
|
+
.map((_, ri) => {
|
|
26
|
+
const info = s.rowInfo?.[ri];
|
|
27
|
+
return info?.hidden
|
|
28
|
+
? ""
|
|
29
|
+
: info?.heightPixels !== undefined
|
|
30
|
+
? `${info.heightPixels}px`
|
|
31
|
+
: "minmax(18px, max-content)";
|
|
32
|
+
})
|
|
33
|
+
.join(" ")}`,
|
|
34
|
+
gridTemplateColumns: `${(s.direction === "col" ? s.cells : colArray)
|
|
35
|
+
.map((_, ci) => {
|
|
36
|
+
const co = s.colInfo?.[ci];
|
|
37
|
+
return co?.hidden
|
|
38
|
+
? ""
|
|
39
|
+
: co?.widthPixels !== undefined
|
|
40
|
+
? `${co.widthPixels}px`
|
|
41
|
+
: "minmax(64px, max-content)";
|
|
42
|
+
})
|
|
43
|
+
.join(" ")}`,
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{s.cells.map((cells, cellsIdx) => (
|
|
47
|
+
<div
|
|
48
|
+
key={cellsIdx}
|
|
49
|
+
className={`cells cells-${cellsIdx}`}
|
|
50
|
+
style={{
|
|
51
|
+
display: "grid",
|
|
52
|
+
...(s.direction === "col"
|
|
53
|
+
? { gridTemplateRows: `subgrid`, gridRow: "1 / -1" }
|
|
54
|
+
: { gridTemplateColumns: `subgrid`, gridColumn: "1 / -1" }),
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
{Array.from({ length: maxCols }, (_, i) => i).map((ci) => {
|
|
58
|
+
const c = cells[ci];
|
|
59
|
+
let s: Partial<Style> = {};
|
|
60
|
+
if (c?.styles !== undefined) {
|
|
61
|
+
for (const style of c.styles) {
|
|
62
|
+
s = { ...s!, ...styles[style] };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
className={`cell cell-${ci} cell-${c?.type}`}
|
|
68
|
+
key={ci}
|
|
69
|
+
style={{
|
|
70
|
+
padding: "1px",
|
|
71
|
+
background: s.foreground,
|
|
72
|
+
justifyContent:
|
|
73
|
+
s.horizontal === "right"
|
|
74
|
+
? "end"
|
|
75
|
+
: s.horizontal === "left"
|
|
76
|
+
? "start"
|
|
77
|
+
: s.horizontal === "center"
|
|
78
|
+
? "center"
|
|
79
|
+
: c?.type === "number"
|
|
80
|
+
? "end"
|
|
81
|
+
: "start",
|
|
82
|
+
display: "flex",
|
|
83
|
+
alignItems:
|
|
84
|
+
s.vertical === "top"
|
|
85
|
+
? "start"
|
|
86
|
+
: s.vertical === "bottom"
|
|
87
|
+
? "end"
|
|
88
|
+
: s.vertical === "center"
|
|
89
|
+
? "center"
|
|
90
|
+
: c?.type === "number"
|
|
91
|
+
? "end"
|
|
92
|
+
: "center ",
|
|
93
|
+
borderTop: `${borderWidth(
|
|
94
|
+
s.borderStyle?.top ?? (s.borderColor?.top ? "medium" : undefined)
|
|
95
|
+
)} ${borderStyle(s.borderStyle?.top)} ${
|
|
96
|
+
s.borderColor?.top ?? s.foreground ?? "rgb(200,200,200)"
|
|
97
|
+
} `,
|
|
98
|
+
borderRight: `${borderWidth(
|
|
99
|
+
s.borderStyle?.right ?? (s.borderColor?.right ? "medium" : undefined)
|
|
100
|
+
)} ${borderStyle(s.borderStyle?.right)} ${
|
|
101
|
+
s.borderColor?.right ?? s.foreground ?? "rgb(200,200,200)"
|
|
102
|
+
} `,
|
|
103
|
+
borderBottom: `${borderWidth(
|
|
104
|
+
s.borderStyle?.bottom ?? (s.borderColor?.bottom ? "medium" : undefined)
|
|
105
|
+
)} ${borderStyle(s.borderStyle?.bottom)} ${
|
|
106
|
+
s.borderColor?.bottom ?? s.foreground ?? "rgb(200,200,200)"
|
|
107
|
+
} `,
|
|
108
|
+
borderLeft: `${borderWidth(
|
|
109
|
+
s.borderStyle?.left ?? (s.borderColor?.left ? "medium" : undefined)
|
|
110
|
+
)} ${borderStyle(s.borderStyle?.left)} ${
|
|
111
|
+
s.borderColor?.left ?? s.foreground ?? "rgb(200,200,200)"
|
|
112
|
+
} `,
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<div
|
|
116
|
+
className={`value value-${ci} value-${c?.type}`}
|
|
117
|
+
style={{
|
|
118
|
+
fontFamily: "calibri",
|
|
119
|
+
textDecoration: [s.strike ? "line-through" : "", s.underline ? "underline" : ""].join(" "),
|
|
120
|
+
fontWeight: s.bold ? "bold" : undefined,
|
|
121
|
+
fontStyle: s.italic ? "italic" : undefined,
|
|
122
|
+
fontSize: `${s.size ?? 11}px`,
|
|
123
|
+
lineHeight: `${s.size ?? 11}px`,
|
|
124
|
+
height: `${s.size ?? 11}px`,
|
|
125
|
+
color: s.color ? s.color : undefined,
|
|
126
|
+
transform: s.textRotation ? `rotate(${s.textRotation})` : undefined,
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
{typeof c?.value === "object" ? c.value.toISOString() : c?.value ?? ""}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
})}
|
|
134
|
+
</div>
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
})}
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function borderWidth(border: BorderStyle | undefined): string {
|
|
144
|
+
switch (border) {
|
|
145
|
+
case "hair":
|
|
146
|
+
case "thin":
|
|
147
|
+
default:
|
|
148
|
+
case undefined:
|
|
149
|
+
return "1px";
|
|
150
|
+
case "thick":
|
|
151
|
+
return "3px";
|
|
152
|
+
case "mediumDashDot":
|
|
153
|
+
case "mediumDashDotDot":
|
|
154
|
+
case "mediumDashed":
|
|
155
|
+
case "dotted":
|
|
156
|
+
case "dashDotDot":
|
|
157
|
+
case "slantDashDot":
|
|
158
|
+
case "dashed":
|
|
159
|
+
case "dashDot":
|
|
160
|
+
case "medium":
|
|
161
|
+
return "2px";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function borderStyle(border: BorderStyle | undefined): string {
|
|
166
|
+
switch (border) {
|
|
167
|
+
case "dashDot":
|
|
168
|
+
case "mediumDashDot":
|
|
169
|
+
case "mediumDashDotDot":
|
|
170
|
+
case "mediumDashed":
|
|
171
|
+
case "dashDotDot":
|
|
172
|
+
case "slantDashDot":
|
|
173
|
+
case "dashed":
|
|
174
|
+
return "dashed";
|
|
175
|
+
case "hair":
|
|
176
|
+
case "dotted":
|
|
177
|
+
return "dotted";
|
|
178
|
+
case undefined:
|
|
179
|
+
case "medium":
|
|
180
|
+
case "thick":
|
|
181
|
+
case "thin":
|
|
182
|
+
default:
|
|
183
|
+
return "solid";
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as XLSX from "xlsx-js-style";
|
|
2
2
|
import { AbstractSheet } from "../abstract-sheet/abstract-sheet";
|
|
3
|
-
import {
|
|
3
|
+
import { xlsxWorkSheet } from "./_xlsx-sheet";
|
|
4
|
+
import { createStyle } from "./_style";
|
|
4
5
|
|
|
5
6
|
export function toXlsx(as: AbstractSheet): Buffer {
|
|
6
7
|
const sheets: Record<string, XLSX.WorkSheet> = {};
|