style-xlsx-m 0.1.12 → 0.1.13
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 +33 -34
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Install browser:
|
|
|
41
41
|
// STEP 1
|
|
42
42
|
// './excample.xlsx' - is a path to your excel file.
|
|
43
43
|
// Second property is a option { cellStyle: true } for get cells style (but now can't get in xls format).
|
|
44
|
-
const workbook = XLSX.readFile('./example.xlsx',{ cellStyles: true
|
|
44
|
+
const workbook = XLSX.readFile('./example.xlsx',{ cellStyles: true });
|
|
45
45
|
|
|
46
46
|
// STEP 2 Create data rows worksheet
|
|
47
47
|
let worksheet = [
|
|
@@ -56,7 +56,7 @@ let worksheet = [
|
|
|
56
56
|
// STEP 3 Get workbook data with style and set workbook.Sheets.sheetname to worksheet
|
|
57
57
|
XLSX.utils.book_append_sheet(workbook, worksheet, false, false, sheetname);
|
|
58
58
|
|
|
59
|
-
// STEP 4 Save your file with style
|
|
59
|
+
// STEP 4 Save your file with style
|
|
60
60
|
XLSX.writeFile(wb, "style-xlsx-m-example.xlsm");
|
|
61
61
|
```
|
|
62
62
|
This example shows how you can change the contents of a file without removing its old style.
|
|
@@ -65,32 +65,10 @@ XLSX.writeFile(wb, "style-xlsx-m-example.xlsm");
|
|
|
65
65
|
## 🗒 Style API
|
|
66
66
|
-- Method to export file in excel with style get from [xlsx-js-style](https://www.npmjs.com/package/xlsx-js-style) (only function writeFile)
|
|
67
67
|
|
|
68
|
-
### Cell Style Example
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
// STEP 1: Create a new workbook
|
|
72
|
-
const wb = XLSX.utils.book_new();
|
|
73
|
-
|
|
74
|
-
// STEP 2: Create data rows and styles
|
|
75
|
-
let row = [
|
|
76
|
-
{ v: "line\nbreak", t: "s", s: { alignment: { wrapText: true } } },
|
|
77
|
-
{ v: "Courier: 24", t: "s", s: { font: { name: "Courier", sz: 24 } } },
|
|
78
|
-
{ v: "fill: color", t: "s", s: { fill: { fgColor: { rgb: "E9E9E9" } } } },
|
|
79
|
-
{ v: "bold & color", t: "s", s: { font: { bold: true, color: { rgb: "FF0000" } } } },
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
// STEP 3: Create worksheet with rows; Add worksheet to workbook
|
|
83
|
-
const ws = XLSX.utils.aoa_to_sheet([row]);
|
|
84
|
-
XLSX.utils.book_append_sheet(wb, ws, "readme demo");
|
|
85
|
-
|
|
86
|
-
// STEP 4: Write Excel file to browser
|
|
87
|
-
XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
|
|
88
|
-
```
|
|
89
|
-
|
|
90
68
|
### Cell Style JSON structure
|
|
91
69
|
|
|
92
70
|
- Cell styles are specified by a style object that roughly parallels the OpenXML structure.
|
|
93
|
-
- Style properties currently supported are: `alignment`, `border`, `fill`, `font
|
|
71
|
+
- Style properties currently supported are: `alignment`, `border`, `fill`, `font`.
|
|
94
72
|
|
|
95
73
|
|
|
96
74
|
```js
|
|
@@ -156,6 +134,29 @@ XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
|
|
|
156
134
|
|
|
157
135
|
```
|
|
158
136
|
|
|
137
|
+
|
|
138
|
+
### Cell Style Example
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
// STEP 1: Create a new workbook
|
|
142
|
+
const wb = XLSX.utils.book_new();
|
|
143
|
+
|
|
144
|
+
// STEP 2: Create data rows and styles
|
|
145
|
+
let row = [
|
|
146
|
+
{ v: "line\nbreak", t: "s", s: { alignment: { wrapText: true } } },
|
|
147
|
+
{ v: "Courier: 24", t: "s", s: { font: { name: "Courier", sz: 24 } } },
|
|
148
|
+
{ v: "fill: color", t: "s", s: { fill: { fgColor: { rgb: "E9E9E9" } } } },
|
|
149
|
+
{ v: "bold & color", t: "s", s: { font: { bold: true, color: { rgb: "FF0000" } } } },
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
// STEP 3: Create worksheet with rows; Add worksheet to workbook
|
|
153
|
+
const ws = XLSX.utils.aoa_to_sheet([row]);
|
|
154
|
+
XLSX.utils.book_append_sheet(wb, ws, "readme demo");
|
|
155
|
+
|
|
156
|
+
// STEP 4: Write Excel file to browser
|
|
157
|
+
XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
|
|
158
|
+
```
|
|
159
|
+
|
|
159
160
|
<!-- | Style Prop | Sub Prop | Default | Description/Values |
|
|
160
161
|
| :---------- | :------------- | :---------- | ------------------------------------------------------------------------------------------------- |
|
|
161
162
|
| `alignment` | `vertical` | `bottom` | `"top"` or `"center"` or `"bottom"` |
|
|
@@ -191,25 +192,23 @@ Colors for `border`, `fill`, `font` are specified as an name/value object - use
|
|
|
191
192
|
|
|
192
193
|
```js
|
|
193
194
|
// JSON structure
|
|
194
|
-
const
|
|
195
|
+
const COLOR_STYLE = { // hex RGB value
|
|
195
196
|
rgb: 'FFCC00'
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
-
const theme = {
|
|
198
|
+
const COLOR_STYLE = { // theme color index
|
|
199
199
|
theme: 4 // (0-n) // Theme color index 4 ("Blue, Accent 1")
|
|
200
200
|
}
|
|
201
|
-
|
|
202
|
-
const tint = {
|
|
201
|
+
const COLOR_STYLE = { // tint by percent
|
|
203
202
|
theme: 1,
|
|
204
|
-
tint: 0.4
|
|
205
|
-
}
|
|
203
|
+
tint: 0.4 // ("Blue, Accent 1, Lighter 40%")
|
|
204
|
+
}
|
|
206
205
|
```
|
|
207
206
|
|
|
208
|
-
| Color Prop | Description | Example |
|
|
207
|
+
<!-- | Color Prop | Description | Example |
|
|
209
208
|
| :--------- | ----------------- | --------------------------------------------------------------- |
|
|
210
209
|
| `rgb` | hex RGB value | `{rgb: "FFCC00"}` |
|
|
211
210
|
| `theme` | theme color index | `{theme: 4}` // (0-n) // Theme color index 4 ("Blue, Accent 1") |
|
|
212
|
-
| `tint` | tint by percent | `{theme: 1, tint: 0.4}` // ("Blue, Accent 1, Lighter 40%") |
|
|
211
|
+
| `tint` | tint by percent | `{theme: 1, tint: 0.4}` // ("Blue, Accent 1, Lighter 40%") | -->
|
|
213
212
|
|
|
214
213
|
### `BORDER_STYLE` {string} Properties
|
|
215
214
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "style-xlsx-m",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"author": "mor8t (Shukurov Shahrom)",
|
|
5
5
|
"description": "style-xlsx-m is a custom xlsx and xlsx-js-style version library",
|
|
6
6
|
"keywords": [
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"bugs": {
|
|
96
96
|
"url": "https://github.com/MOR8T/STYLE-XSLX-M"
|
|
97
97
|
},
|
|
98
|
-
"license": "Apache-
|
|
98
|
+
"license": "Apache-2.0",
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=0.8"
|
|
101
101
|
}
|