Sheets

Add support for Spreadsheets to store data.

Options See on deno.land

extensions string[]

Extensions processed by this plugin

Default:
[ ".xlsx", ".numbers", ".csv" ]
sheets first auto

Return the first sheet only or all sheets if the document have more

Default:
"auto"
options object

Options passed to Sheetjs

type base64 binary buffer file array string

Input data encoding

codepage number

Default codepage for legacy files

This requires encoding support to be loaded. It is automatically loaded in xlsx.full.min.js and in CommonJS / Extendscript, but an extra step is required in React / Angular / Webpack ESM deployments.

Check the relevant guide https://docs.sheetjs.com/docs/getting-started/

cellFormula boolean

Save formulae to the .f field

Default:
true
cellHTML boolean

Parse rich text and save HTML to the .h field

Default:
true
cellNF boolean

Save number format string to the .z field

Default:
false
cellText boolean

Generate formatted text to the .w field

Default:
true
dateNF string

Override default date format (code 14)

FS string

Field Separator ("Delimiter" override)

sheetRows number

If >0, read the first sheetRows rows

Default:
0
bookDeps boolean

If true, parse calculation chains

Default:
false
bookFiles boolean

If true, add raw files to book object

Default:
false
bookProps boolean

If true, only parse enough to get book metadata

Default:
false
bookSheets boolean

If true, only parse enough to get the sheet names

Default:
false
sheets number string object

If specified, only parse the specified sheets or sheet names

raw boolean

If true, plaintext parsing will not parse values

nodim boolean

If true, ignore "dimensions" records and guess range using every cell

xlfn boolean

If true, preserve _xlfn. prefixes in formula function names

dense boolean
PRN boolean

Description

This plugin use SheetJS to read any spreadsheet document as _data files, so you can use this data to render your pages.

Installation

Import this plugin in your _config.ts file to use it:

import lume from "lume/mod.ts";
import sheets from "lume/plugins/sheets.ts";

const site = lume();

site.use(sheets());

export default site;

Formats

By default, it loads the .xlsx, .numbers and .csv files. You can use any extension supported by SheetJS. See the file formats documentation for more info.

import lume from "lume/mod.ts";
import sheets from "lume/plugins/sheets.ts";

const site = lume();

site.use(sheets({
  extensions: [".ods", "rtf", "xls"],
}));

export default site;

Sheet mode

The plugin can work in two sheet modes: first and auto.

First

In the first sheet mode, only the first sheet found in the document is returned, even if it contains more. For example a file stored in _data/people.xlsx containing two sheets, only the first one is returned:

<table>
  <tr>
    {{ for key, column of people[0] }}
      <th>{{ key }}</th>
    {{ /for }}
  </tr>

  {{ for row of people }}
    <tr>
      {{ for key, column of row }}
        <td>{{ column }}</td>
      {{ /for }}
    </tr>
  {{ /for }}
</table>

Auto

If the sheets value is set to auto, it returns all sheets found in the document and you have to use the sheet name to access to its content.

For example, if the file _data/people.xlsx contains the sheets "Women" and "Men", you can access to the data in this way:

<h1>Women</h1>
<ul>
  {{ for person of people["Women"] }}
    <li>
      {{ person.name }} - {{ person.surname }}
    </li>
  {{ /for }}
</ul>

<h1>Men</h1>
<ul>
  {{ for person of people["Men"] }}
    <li>
      {{ person.name }} - {{ person.surname }}
    </li>
  {{ /for }}
</ul>

If the spreadsheet contain only one sheet, you don't have to access to the data by the name. In this case it works exactly as the "first" mode.

The default mode is auto, to change it to first:

import lume from "lume/mod.ts";
import sheets from "lume/plugins/sheets.ts";

const site = lume();

site.use(sheets({
  sheets: "first", // Return the first sheet found in each document
}));

export default site;