sheetjs/docbits/53_wsobject.md

49 lines
2.2 KiB
Markdown
Raw Normal View History

2017-03-31 21:46:02 +00:00
### Sheet Objects
Each key that does not start with `!` maps to a cell (using `A-1` notation)
2017-03-31 21:46:02 +00:00
`sheet[address]` returns the cell object for the specified address.
**Special sheet keys (accessible as `sheet[key]`, each starting with `!`):**
2017-03-31 21:46:02 +00:00
- `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
are assigned outside of the range are not processed. In particular, when
2017-03-31 21:46:02 +00:00
writing a sheet by hand, cells outside of the range are not included
2017-03-31 21:46:02 +00:00
Functions that handle sheets should test for the presence of `!ref` field.
If the `!ref` is omitted or is not a valid range, functions are free to treat
the sheet as empty or attempt to guess the range. The standard utilities that
ship with this library treat sheets as empty (for example, the CSV output is
empty string).
When reading a worksheet with the `sheetRows` property set, the ref parameter
will use the restricted range. The original range is set at `ws['!fullref']`
- `sheet['!margins']`: Object representing the page margins. The default values
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>
2017-09-24 23:40:09 +00:00
<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` |
| `right` | right margin (inches) | `0.7` | `1.0` | `0.25` |
| `top` | top margin (inches) | `0.75` | `1.0` | `0.75` |
| `bottom` | bottom margin (inches) | `0.75` | `1.0` | `0.75` |
| `header` | header margin (inches) | `0.3` | `0.5` | `0.3` |
| `footer` | footer margin (inches) | `0.3` | `0.5` | `0.3` |
```js
/* Set worksheet sheet to "normal" */
2017-09-24 23:40:09 +00:00
ws["!margins"]={left:0.7, right:0.7, top:0.75,bottom:0.75,header:0.3,footer:0.3}
/* Set worksheet sheet to "wide" */
2017-09-24 23:40:09 +00:00
ws["!margins"]={left:1.0, right:1.0, top:1.0, bottom:1.0, header:0.5,footer:0.5}
/* Set worksheet sheet to "narrow" */
2017-09-24 23:40:09 +00:00
ws["!margins"]={left:0.25,right:0.25,top:0.75,bottom:0.75,header:0.3,footer:0.3}
```
</details>