Skip to content

Commit

Permalink
browser tests and doc cleanup [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
SheetJSDev committed May 1, 2017
1 parent b9bc0a1 commit 810c447
Show file tree
Hide file tree
Showing 31 changed files with 1,160 additions and 266 deletions.
335 changes: 284 additions & 51 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bits/62_fxls.js
Expand Up @@ -775,6 +775,7 @@ function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks,
case 'PtgRef3d': // TODO: lots of stuff
type = f[1][0]; ixti = /*::Number(*/f[1][1]/*::)*/; c = shift_cell_xls(f[1][2], _range, opts);
sname = supbooks.SheetNames[ixti];
var w = sname; /* IE9 fails on defined names */
stack.push(sname + "!" + encode_cell_xls(c));
break;

Expand Down
4 changes: 4 additions & 0 deletions docbits/00_intro.md
Expand Up @@ -22,6 +22,10 @@ enhancements and additional features by request.

![circo graph of format support](formats.png)

<details>
<summary>Graph Legend</summary>

![graph legend](legend.png)

</details>

4 changes: 4 additions & 0 deletions docbits/01_toc.md
@@ -1,4 +1,8 @@
## Table of Contents

<details>
<summary>Expand to show Table of Contents</summary>

<!-- toc -->
</details>

38 changes: 29 additions & 9 deletions docbits/20_import.md
Expand Up @@ -3,23 +3,32 @@
For parsing, the first step is to read the file. This involves acquiring the
data and feeding it into the library. Here are a few common scenarios:

- node readFile:
<details>
<summary><b>nodejs read a file</b> (click to show)</summary>

```js
if(typeof require !== 'undefined') XLSX = require('xlsx');
var workbook = XLSX.readFile('test.xlsx');
/* DO SOMETHING WITH workbook HERE */
```

- Browser DOM Table element:
</details>

<details>
<summary><b>Browser read TABLE element from page</b> (click to show)</summary>

```js
var worksheet = XLSX.utils.table_to_book(document.getElementById('tableau'));
/* DO SOMETHING WITH workbook HERE */
```

- ajax (for a more complete example that works in older browsers, check the demo
at <http://oss.sheetjs.com/js-xlsx/ajax.html>):
</details>

<details>
<summary><b>Browser download file (ajax)</b> (click to show)</summary>

Note: for a more complete example that works in older browsers, check the demo
at <http://oss.sheetjs.com/js-xlsx/ajax.html>):

```js
/* set up XMLHttpRequest */
Expand All @@ -46,9 +55,14 @@ oReq.onload = function(e) {
oReq.send();
```

- HTML5 drag-and-drop using readAsBinaryString or readAsArrayBuffer:
note: readAsBinaryString and readAsArrayBuffer may not be available in every
browser. Use dynamic feature tests to determine which method to use.
</details>

<details>
<summary><b>Browser drag-and-drop</b> (click to show)</summary>

Drag-and-drop uses FileReader with readAsBinaryString or readAsArrayBuffer.
Note: readAsBinaryString and readAsArrayBuffer may not be available in every
browser. Use dynamic feature tests to determine which method to use.

```js
/* processing array buffers, only required for readAsArrayBuffer */
Expand Down Expand Up @@ -92,7 +106,10 @@ function handleDrop(e) {
drop_dom_element.addEventListener('drop', handleDrop, false);
```

- HTML5 input file element using readAsBinaryString or readAsArrayBuffer:
</details>

<details>
<summary><b>Browser file upload form element</b> (click to show)</summary>

```js
/* fixdata and rABS are defined in the drag and drop example */
Expand Down Expand Up @@ -124,7 +141,10 @@ function handleFile(e) {
input_dom_element.addEventListener('change', handleFile, false);
```

**Complete examples:**
</details>


### Complete Examples

- <http://oss.sheetjs.com/js-xlsx/> HTML5 File API / Base64 Text / Web Workers

Expand Down
2 changes: 1 addition & 1 deletion docbits/25_manip.md
Expand Up @@ -18,7 +18,7 @@ var desired_cell = worksheet[address_of_cell];
var desired_value = (desired_cell ? desired_cell.v : undefined);
```

**Complete examples:**
### Complete Examples

- <https://github.com/SheetJS/js-xlsx/blob/master/bin/xlsx.njs> node

Expand Down
20 changes: 13 additions & 7 deletions docbits/30_export.md
Expand Up @@ -5,19 +5,25 @@ For writing, the first step is to generate output data. The helper functions
dissemination. The second step is to actual share the data with the end point.
Assuming `workbook` is a workbook object:

- nodejs write to file:
<details>
<summary><b>nodejs write a file</b> (click to show)</summary>

```js
/* output format determined by filename */
XLSX.writeFile(workbook, 'out.xlsx');
/* at this point, out.xlsx is a file that you can distribute */
```

- browser generate binary blob and "download" to client
(using [FileSaver.js](https://github.com/eligrey/FileSaver.js/) for download):
</details>

<details>
<summary><b>Browser download file</b> (click to show)</summary>

Note: browser generates binary blob and forces a "download" to client. This
example uses [FileSaver.js](https://github.com/eligrey/FileSaver.js/):

```js
/* bookType can be 'xlsx' or 'xlsm' or 'xlsb' or 'ods' */
/* bookType can be any supported output type */
var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };

var wbout = XLSX.write(workbook,wopts);
Expand All @@ -32,10 +38,10 @@ function s2ab(s) {
/* the saveAs call downloads a file on the local machine */
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "test.xlsx");
```
</details>

**Complete examples:**
### Complete Examples

- <http://sheetjs.com/demos/writexlsx.html> generates a simple file
- <http://git.io/WEK88Q> writing an array of arrays in nodejs
- <http://sheetjs.com/demos/table.html> exporting an HTML table
- <http://sheetjs.com/demos/writexlsx.html> generates a simple file

1 change: 1 addition & 0 deletions docbits/31_writestream.md
Expand Up @@ -8,3 +8,4 @@ stream. They are only exposed in node.
- `XLSX.stream.to_html` is the streaming version of the HTML output type.

<https://github.com/sheetjs/sheetaki> pipes write streams to nodejs response.

5 changes: 5 additions & 0 deletions docbits/52_datatype.md
Expand Up @@ -6,6 +6,9 @@ Type `b` is the Boolean type. `v` is interpreted according to JS truth tables.

Type `e` is the Error type. `v` holds the number and `w` holds the common name:

<details>
<summary><b>Error values and interpretation</b> (click to show)</summary>

| Value | Error Meaning |
| -----: | :-------------- |
| `0x00` | `#NULL!` |
Expand All @@ -17,6 +20,8 @@ Type `e` is the Error type. `v` holds the number and `w` holds the common name:
| `0x2A` | `#N/A` |
| `0x2B` | `#GETTING_DATA` |

</details>

Type `n` is the Number type. This includes all forms of data that Excel stores
as numbers, such as dates/times and Boolean fields. Excel exclusively uses data
that can be fit in an IEEE754 floating point number, just like JS Number, so the
Expand Down
6 changes: 5 additions & 1 deletion docbits/53_wsobject.md
Expand Up @@ -4,7 +4,7 @@ Each key that does not start with `!` maps to a cell (using `A-1` notation)

`sheet[address]` returns the cell object for the specified address.

Special sheet keys (accessible as `sheet[key]`, each starting with `!`):
**Special sheet keys (accessible as `sheet[key]`, each starting with `!`):**

- `sheet['!ref']`: A-1 based range representing the sheet range. Functions that
work with sheets should use this parameter to determine the range. Cells that
Expand All @@ -24,6 +24,9 @@ Special sheet keys (accessible as `sheet[key]`, each starting with `!`):
follow Excel's "normal" preset. Excel also has a "wide" and a "narrow" preset
but they are stored as raw measurements. The main properties are listed below:

<details>
<summary><b>Page margin details</b> (click to show)</summary>

| key | description | "normal" | "wide" | "narrow" |
|----------|------------------------|:---------|:-------|:-------- |
| `left` | left margin (inches) | `0.7` | `1.0` | `0.25` |
Expand All @@ -41,4 +44,5 @@ sheet["!margins"] = { left:1.0, right:1.0, top:1.0, bottom:1.0, header:0.5, foot
/* Set worksheet sheet to "narrow" */
sheet["!margins"] = { left:0.25, right:0.25, top:0.75, bottom:0.75, header:0.3, footer:0.3 }
```
</details>

4 changes: 4 additions & 0 deletions docbits/54_shobject.md
Expand Up @@ -22,6 +22,9 @@ In addition to the base sheet keys, worksheets also add:
keys control the sheet protection -- set to `false` to enable a feature when
sheet is locked or set to `true` to disable a feature:

<details>
<summary><b>Worksheet Protection Details</b> (click to show)</summary>

| key | feature (true=disabled / false=enabled) | default |
|:----------------------|:----------------------------------------|:-----------|
| `selectLockedCells` | Select locked cells | enabled |
Expand All @@ -39,6 +42,7 @@ In addition to the base sheet keys, worksheets also add:
| `pivotTables` | Use PivotTable reports | disabled |
| `objects` | Edit objects | enabled |
| `scenarios` | Edit scenarios | enabled |
</details>

- `ws['!autofilter']`: AutoFilter object following the schema:

Expand Down
4 changes: 4 additions & 0 deletions docbits/56_wbprops.md
Expand Up @@ -3,6 +3,9 @@
The various file formats use different internal names for file properties. The
workbook `Props` object normalizes the names:

<details>
<summary><b>File Properties</b> (click to show)</summary>

| JS Name | Excel Description |
|:------------|:-------------------------------|
| Title | Summary tab "Title" |
Expand All @@ -15,6 +18,7 @@ workbook `Props` object normalizes the names:
| Comments | Summary tab "Comments" |
| LastAuthor | Statistics tab "Last saved by" |
| CreatedDate | Statistics tab "Created" |
</details>

For example, to set the workbook title property:

Expand Down
4 changes: 4 additions & 0 deletions docbits/57_wbbook.md
Expand Up @@ -6,12 +6,16 @@

`wb.Workbook.Names` is an array of defined name objects which have the keys:

<details>
<summary><b>Defined Name Properties</b> (click to show)</summary>

| Key | Description |
|:----------|:-----------------------------------------------------------------|
| `Sheet` | Name scope. Sheet Index (0 = first sheet) or `null` (Workbook) |
| `Name` | Case-sensitive name. Standard rules apply ** |
| `Ref` | A1-style Reference (e.g. `"Sheet1!$A$1:$D$20"`) |
| `Comment` | Comment (only applicable for XLS/XLSX/XLSB) |
</details>

Excel allows two sheet-scoped defined names to share the same name. However, a
sheet-scoped name cannot collide with a workbook-scope name. Workbook writers
Expand Down
21 changes: 18 additions & 3 deletions docbits/61_formulae.md
Expand Up @@ -5,7 +5,8 @@ file formats store the formulae in different ways, the formats are translated.
Even though some formats store formulae with a leading equal sign, CSF formulae
do not start with `=`.

The worksheet representation of A1=1, A2=2, A3=A1+A2:
<details>
<summary><b>Representation of A1=1, A2=2, A3=A1+A2</b> (click to show)</summary>

```js
{
Expand All @@ -15,6 +16,7 @@ The worksheet representation of A1=1, A2=2, A3=A1+A2:
A3: { t:'n', v:3, f:'A1+A2' }
}
```
</details>

Shared formulae are decompressed and each cell has the formula corresponding to
its cell. Writers generally do not attempt to generate shared formulae.
Expand All @@ -23,6 +25,9 @@ Cells with formula entries but no value will be serialized in a way that Excel
and other spreadsheet tools will recognize. This library will not automatically
compute formula results! For example, to compute `BESSELJ` in a worksheet:

<details>
<summary><b>Formula without known value</b> (click to show)</summary>

```js
{
"!ref": "A1:A3",
Expand All @@ -31,13 +36,17 @@ compute formula results! For example, to compute `BESSELJ` in a worksheet:
A3: { t:'n', f:'BESSELJ(A1,A2)' }
}
```
</details>

**Array Formulae**

Array formulae are stored in the top-left cell of the array block. All cells
of an array formula have a `F` field corresponding to the range. A single-cell
formula can be distinguished from a plain formula by the presence of `F` field.

<details>
<summary><b>Array Formula examples</b> (click to show)</summary>

For example, setting the cell `C1` to the array formula `{=SUM(A1:A3*B1:B3)}`:

```js
Expand All @@ -53,18 +62,23 @@ worksheet['D2'] = { t:'n', F:"D1:D3" };
worksheet['D3'] = { t:'n', F:"D1:D3" };
```

</details>

Utilities and writers are expected to check for the presence of a `F` field and
ignore any possible formula element `f` in cells other than the starting cell.
They are not expected to perform validation of the formulae!

**Formula Output**
<details>
<summary><b>Formula Output Utility Function</b> (click to show)</summary>

The `sheet_to_formulae` method generates one line per formula or array formula.
Array formulae are rendered in the form `range=formula` while plain cells are
rendered in the form `cell=formula or value`. Note that string literals are
prefixed with an apostrophe `'`, consistent with Excel's formula bar display.
</details>

**Formulae File Format Details**
<details>
<summary><b>Formulae File Format Details</b> (click to show)</summary>

| Storage Representation | Formats | Read | Write |
|:-----------------------|:-------------------------|:-----:|:-----:|
Expand All @@ -77,4 +91,5 @@ Since Excel prohibits named cells from colliding with names of A1 or RC style
cell references, a (not-so-simple) regex conversion is possible. BIFF Parsed
formulae have to be explicitly unwound. OpenFormula formulae can be converted
with regexes for the most part.
</details>

0 comments on commit 810c447

Please sign in to comment.