Skip to content

Commit 41eff6b

Browse files
committed
Update documentation
1 parent 8cbb5fb commit 41eff6b

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

README.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414

1515
- As part of the new version 3.0.0+, there is support for _XLSX_. The drawback is that the library is 200+ KB.
1616

17-
- If you only need _XLS_ or _CSV_, use _2.X.X_ versions.
18-
1917
- Check My Blog Page for Testing :
2018
[JavaScript export to Excel](http://jordiburgos.com/post/2013/javascript-export-to-excel.html)
2119

2220
[ExcellentExport.js update: JavaScript export to Excel and CSV](http://jordiburgos.com/post/2017/excellentexport-javascript-export-to-excel-csv.html)
2321

2422
# Revision history:
2523

24+
### 3.9.0
25+
26+
* Cell types and formats!!! Now you can define the cell type and format. For example, you can define a cell as a date or a number. You can also define the format of the cell. For example, you can define a cell as a date with the format "dd/mm/yyyy" or a number with the format "#,##0.00".
27+
2628
### 3.8.1
2729

2830
* Activate XLSX compression by default. The example of index.bigtable.html went from 18Mb to 3Mb.
@@ -241,6 +243,7 @@
241243
fixValue: function(value, row, column) {return fixedValue} // Function to fix values, receiving value, row num, column num
242244
fixArray: function(array) {return array} // Function to manipulate the whole data array
243245
rtl: Use Right-to-left characters, boolean (optional)
246+
formats: [...] // Array of formats for each column. See formats below.
244247
...
245248
},
246249
{
@@ -259,6 +262,47 @@ It transforms BR to line breaks and then strips all the HTML tags.
259262
return strippedString;
260263
}
261264

265+
## Formats
266+
267+
You can specify an array with the formats for a specific cell range (i.e. A1:A100, A1:D100, A1:H1, etc).
268+
269+
Each element in the format array consists on:
270+
271+
```json
272+
{
273+
"range": "A1:A100", // Range of cells to apply the format, mandatory
274+
"format": {
275+
"type": "<cell_type>", // Type of format, mandatory
276+
"pattern": "<pattern>" // Pattern, optional
277+
}
278+
}
279+
```
280+
281+
`format` can be used from one of the predefined types if you use TypeScript
282+
283+
```typescript
284+
{
285+
"range": "A1:A100",
286+
"format": PredefinedFormat.INTEGER
287+
}
288+
```
289+
290+
`cell_type` can be one of the followint:
291+
292+
's': String
293+
'n': Number
294+
'd': Date
295+
'b': Boolean
296+
297+
`pattern` is a string with the format pattern used in Excel. For example:
298+
299+
'0' // Integer
300+
'0.00' // 2 decimals
301+
'dd/mm/yyyy' // Date
302+
'dd/mm/yyyy hh:mm:ss' // Date and time
303+
'0.00%' // Percentage
304+
'0.00e+00' // Scientific notation
305+
'@' // Text
262306

263307
# Notes
264308

index.format.html

+12-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{ range: "C2:C10", format: ExcellentExport.formats.DATE },
2727
{ range: "D2:D10", format: ExcellentExport.formats.DECIMAL },
2828
{ range: "E2:E10", format: ExcellentExport.formats.BOOLEAN },
29+
{ range: "F2:F10", format: ExcellentExport.formats.INTEGER },
2930
{ range: "A5:E5", format: ExcellentExport.formats.TEXT },
3031
{ range: "A6", format: ExcellentExport.formats.DECIMAL },
3132
],
@@ -46,47 +47,54 @@ <h3>Test page</h3>
4647
<th>Birthdate</th>
4748
<th>Salary</th>
4849
<th>Active</th>
50+
<th>Big number</th>
4951
</tr>
5052
<tr>
5153
<td>1</td>
5254
<td>John</td>
5355
<td>1980-12-10</td>
54-
<td>2000.55</td>
56+
<td>98762000.55</td>
5557
<td>1</td>
58+
<td>987654321987654</td>
5659
</tr>
5760
<tr>
5861
<td>2</td>
5962
<td>Peter</td>
6063
<td>1978-01-23</td>
61-
<td>2500.43</td>
64+
<td>98762500.43</td>
6265
<td>0</td>
66+
<td>876543219987654</td>
6367
</tr>
6468
<tr>
6569
<td>3</td>
6670
<td>George</td>
6771
<td>1985-11-30</td>
68-
<td>1800.98</td>
72+
<td>98761800.98</td>
6973
<td>1</td>
74+
<td>765432198987654</td>
7075
</tr>
7176
<tr>
7277
<td>End</td>
7378
<td>End</td>
7479
<td>End</td>
7580
<td>End</td>
7681
<td>End</td>
82+
<td>End</td>
7783
</tr>
7884
<tr>
7985
<td>9876543.21</td>
8086
<td></td>
8187
<td></td>
8288
<td></td>
8389
<td></td>
90+
<td></td>
8491
</tr>
8592
</table>
8693

8794
<br/>
8895

89-
<a href="#" id="anchorNewApi-xlsx" onclick="return newApi('xlsx');">Export</a>
96+
<a href="#" id="anchorNewApi-xlsx" onclick="return newApi('xlsx');">Export Excel</a>
97+
<a href="#" id="anchorNewApi-csv" onclick="return newApi('csv');">Export CSV</a>
9098

9199
</body>
92100
</html>

src/excellentexport.ts

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ export interface FromOptions {
3131
array?: any[][],
3232
}
3333

34-
35-
3634
export interface SheetOptions {
3735
name: string,
3836
from: FromOptions,

0 commit comments

Comments
 (0)