--- title: ViteJS Spreadsheet Plugins sidebar_class_name: red sidebar_label: ViteJS description: Make static websites from spreadsheets using ViteJS. Seamlessly integrate data into your website using SheetJS. Empower non-technical people to write content from Excel. pagination_prev: demos/net/index pagination_next: demos/mobile/index sidebar_custom_props: type: bundler --- import current from '/version.js'; import CodeBlock from '@theme/CodeBlock'; [ViteJS](https://vitejs.dev/) is a build tool for generating static websites. It has a robust JavaScript-powered plugin system[^1]. [SheetJS](https://sheetjs.com) is a JavaScript library for reading and writing data from spreadsheets. This demo uses ViteJS and SheetJS to pull data from a spreadsheet and display the content in an HTML table. We'll explore how to load SheetJS in a ViteJS plugin and evaluate data loading strategies. The ["Complete Demo"](#complete-demo) section creates a complete website powered by a XLSX spreadsheet. :::info pass This demo covers use cases where data is available at build time. This flow is suitable for end of week or end of month (EOM) reports published in HTML tables. For processing user-submitted files in the browser, the [ViteJS "Bundlers" demo](/docs/demos/frontend/bundler/vitejs) shows client-side bundling of SheetJS libraries. The ["ReactJS" demo](/docs/demos/frontend/react) shows example sites using ViteJS with the ReactJS starter. ::: ## Plugins ViteJS supports static asset imports[^2], but the default raw loader interprets data as UTF-8 strings. This corrupts binary formats including XLSX and XLS. A custom loader can bypass the raw loader and directly read files. Since a custom loader must be used, some data processing work can be performed by the loader. Three approaches are explored in this demo. The following diagrams show the ViteJS data flow. The pink "Main Script import" boxes represent the division between the loader and the main script. The green "SheetJS Operations" boxes represent the steps performed by SheetJS libraries.
[HTML](#html-plugin) | [Data](#pure-data-plugin) | [Base64](#base64-plugin) |
---|---|---|
```mermaid flowchart TB file[(workbook\nfile)] buffer(NodeJS\nBuffer) sheetjs[[SheetJS Operations]] tabeller{{HTML\nString}} handoff[[Main Script import]] html{{HTML\nTABLE}} style handoff fill:#FFC7CE style sheetjs fill:#C6EFCE file --> buffer buffer --> sheetjs sheetjs --> tabeller tabeller --> handoff handoff --------> html ``` | ```mermaid flowchart TB file[(workbook\nfile)] buffer(NodeJS\nBuffer) sheetjs[[SheetJS Operations]] aoo(array of\nobjects) handoff[[Main Script import]] import(array of\nobjects) html{{HTML\nTABLE}} style handoff fill:#FFC7CE style sheetjs fill:#C6EFCE file --> buffer buffer --> sheetjs sheetjs --> aoo aoo --> handoff handoff ------> import import --> html ``` | ```mermaid flowchart TB file[(workbook\nfile)] base64(Base64\nString) handoff[[Main Script import]] import(Base64\nString) sheetjs[[SheetJS Operations]] aoo(array of\nobjects) html{{HTML\nTABLE}} style handoff fill:#FFC7CE style sheetjs fill:#C6EFCE file --> base64 base64 ------> handoff handoff --> import import --> sheetjs sheetjs --> aoo aoo --> html ``` |
Name | Index |
---|---|
${row.Name} | ${row.Index} |
Name | Index |
---|---|
${row.Name} | ${row.Index} |
Name | Index |
---|---|
{{row.Name}} | {{row.Index}} |
Name | Index |
---|---|
{{row.Name}} | {{row.Index}} |