sheetjs_sheetjs/docbits/53_wsobject.md
SheetJS 1587688aea Page Margins
- XLSB read/write page margins
- XLSX/XLS/XLML read page margins
- separated encrypted XLSX/XLSB document logic from XLS
2017-04-12 21:29:38 -04:00

2.2 KiB

Sheet Objects

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 !):

  • 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 writing a sheet by hand, cells outside of the range are not included

    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:

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
/* Set worksheet sheet to "normal" */
sheet["!margins"] = { left:0.7, right:0.7, top:0.75, bottom:0.75, header:0.3, footer:0.3 }
/* Set worksheet sheet to "wide" */
sheet["!margins"] = { left:1.0, right:1.0, top:1.0, bottom:1.0, header:0.5, footer:0.5 }
/* 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 }