docs.sheetjs.com/docz/docs/07-csf/03-book.md

108 lines
3.6 KiB
Markdown
Raw Normal View History

2022-05-16 03:26:04 +00:00
---
sidebar_position: 3
---
# Workbook Object
`workbook.SheetNames` is an ordered list of the sheets in the workbook
`wb.Sheets[sheetname]` returns an object representing the worksheet.
`wb.Props` is an object storing the standard properties. `wb.Custprops` stores
custom properties. Since the XLS standard properties deviate from the XLSX
standard, XLS parsing stores core properties in both places.
`wb.Workbook` stores [workbook-level attributes](#workbook-level-attributes).
## File Properties
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" |
| `Subject` | Summary tab "Subject" |
| `Author` | Summary tab "Author" |
| `Manager` | Summary tab "Manager" |
| `Company` | Summary tab "Company" |
| `Category` | Summary tab "Category" |
| `Keywords` | Summary tab "Keywords" |
| `Comments` | Summary tab "Comments" |
| `LastAuthor` | Statistics tab "Last saved by" |
| `CreatedDate` | Statistics tab "Created" |
</details>
For example, to set the workbook title property:
```js
if(!wb.Props) wb.Props = {};
wb.Props.Title = "Insert Title Here";
```
Custom properties are added in the workbook `Custprops` object:
```js
if(!wb.Custprops) wb.Custprops = {};
wb.Custprops["Custom Property"] = "Custom Value";
```
Writers will process the `Props` key of the options object:
```js
/* force the Author to be "SheetJS" */
XLSX.write(wb, {Props:{Author:"SheetJS"}});
```
## Workbook-Level Attributes
`wb.Workbook` stores workbook-level attributes.
### Defined Names
<details>
<summary><b>Format Support</b> (click to show)</summary>
**Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK
**Unicode Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML
**Defined Name Comment**: XLSX/M, XLSB, BIFF8 XLS
</details>
`wb.Workbook.Names` is an array of defined name objects which have the keys:
| Key | Description |
|:----------|:-----------------------------------------------------------------|
| `Sheet` | Name scope. Sheet Index (0 = first sheet) or `null` (Workbook) |
| `Name` | Case-sensitive name. Standard rules apply ** |
| `Ref` | A1-style Reference (`"Sheet1!$A$1:$D$20"`) |
| `Comment` | Comment (only applicable for XLS/XLSX/XLSB) |
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
may not enforce this constraint.
### Workbook Views
`wb.Workbook.Views` is an array of workbook view objects which have the keys:
| Key | Description |
|:----------------|:----------------------------------------------------|
| `RTL` | If true, display right-to-left |
### Miscellaneous Workbook Properties
`wb.Workbook.WBProps` holds other workbook properties:
| Key | Description |
|:----------------|:----------------------------------------------------|
| `CodeName` | [VBA Workbook Code Name](./features#vba-and-macros) |
| `date1904` | epoch: 0/false for 1900 system, 1/true for 1904 |
| `filterPrivacy` | Warn or strip personally identifying info on save |