forked from sheetjs/docs.sheetjs.com
sqlite
This commit is contained in:
parent
94d2754778
commit
8dec73b809
10
Makefile
10
Makefile
@ -6,9 +6,17 @@ build:
|
||||
mv docz/build/ docs
|
||||
cp CNAME docs
|
||||
|
||||
.PHONY: init
|
||||
init:
|
||||
cd docz; npm i; cd ..
|
||||
|
||||
.PHONY: dev
|
||||
dev:
|
||||
cd docz; npm run start; cd ..
|
||||
|
||||
.PHONY: serve
|
||||
serve:
|
||||
cd docs; python -mSimpleHTTPServer || python3 -mhttp.server; cd -
|
||||
npx -y http-server docs
|
||||
|
||||
.PHONY: spell
|
||||
spell:
|
||||
|
32
README.md
32
README.md
@ -1,3 +1,35 @@
|
||||
# SheetJS CE Docs
|
||||
|
||||
Hosted URL: <https://docs.sheetjs.com>
|
||||
|
||||
## Development
|
||||
|
||||
`docz/version.js` exports a version number for use in docs pages.
|
||||
|
||||
Build commands:
|
||||
|
||||
```bash
|
||||
$ make init # install dependencies
|
||||
$ make # build static site
|
||||
$ make serve # serve static site
|
||||
|
||||
$ make dev # run dev server
|
||||
$ make spell # spell check (.spelling custom dictionary)
|
||||
$ make graph # build format graph and legend
|
||||
```
|
||||
|
||||
## Live Demos
|
||||
|
||||
**Imports do not work from live codeblocks!**
|
||||
|
||||
<https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js> is loaded
|
||||
on each page, making the `XLSX` variable available to live blocks.
|
||||
|
||||
Specific pages can load scripts using the `head` component:
|
||||
|
||||
```html
|
||||
<head>
|
||||
<script src="https://cdn.sheetjs.com/xspreadsheet/xlsxspread.min.js"></script>
|
||||
</head>
|
||||
```
|
||||
|
||||
|
@ -119,7 +119,7 @@ import { read, writeFileXLSX } from "https://cdn.sheetjs.com/xlsx-${current}/pac
|
||||
</script>`}
|
||||
</code></pre>
|
||||
|
||||
If XLS support is required, `cpexcel.full.mjs` must be manually imported:
|
||||
If Encoding support is required, `cpexcel.full.mjs` must be manually imported:
|
||||
|
||||
<pre><code parentName="pre" {...{"className": "language-html"}}>{`\
|
||||
<script type="module">
|
||||
|
@ -78,9 +78,9 @@ yarn add https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz`}
|
||||
|
||||
:::
|
||||
|
||||
## XLS Support
|
||||
## Encoding support
|
||||
|
||||
If XLS support is required, `cpexcel.full.mjs` must be manually imported:
|
||||
If Encoding support is required, `cpexcel.full.mjs` must be manually imported:
|
||||
|
||||
```js
|
||||
/* load the codepage support library for extended support with older formats */
|
||||
|
@ -32,9 +32,9 @@ but the Deno registry is out of date.
|
||||
|
||||
:::
|
||||
|
||||
## XLS Support
|
||||
## Encoding support
|
||||
|
||||
If XLS support is required, `cpexcel.full.mjs` must be manually imported:
|
||||
If Encoding support is required, `cpexcel.full.mjs` must be manually imported:
|
||||
|
||||
<pre><code parentName="pre" {...{"className": "language-ts"}}>{`\
|
||||
/* load the codepage support library for extended support with older formats */
|
||||
|
@ -27,11 +27,13 @@ After downloading the script, it can be directly imported:
|
||||
|
||||
```js
|
||||
import * as XLSX from './xlsx.mjs';
|
||||
import * as fs from 'fs';
|
||||
XLSX.set_fs(fs);
|
||||
```
|
||||
|
||||
## XLS Support
|
||||
## Encoding support
|
||||
|
||||
If XLS support is required, `cpexcel.full.mjs` must be manually imported.
|
||||
If Encoding support is required, `cpexcel.full.mjs` must be manually imported.
|
||||
|
||||
<div><a href={`https://cdn.sheetjs.com/xlsx-${current}/package/dist/cpexcel.full.mjs`}>https://cdn.sheetjs.com/xlsx-{current}/package/dist/cpexcel.full.mjs</a> is the URL for {current}</div><br/>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Data Grids and UI
|
||||
title: Data Grids and Tables
|
||||
---
|
||||
|
||||
Various JavaScript UI components provide a more interactive editing experience.
|
||||
|
@ -270,8 +270,7 @@ The following example shows how to query for each table in an SQLite database,
|
||||
query for the data for each table, add each non-empty table to a workbook, and
|
||||
export as XLSX.
|
||||
|
||||
[The Northwind database is available in SQLite form](https://github.com/jpwhite3/northwind-SQLite3/raw/master/Northwind_large.sqlite.zip).
|
||||
Download and expand the zip archive to reveal `Northwind_large.sqlite`
|
||||
[The Northwind database is available in SQLite form](https://raw.githubusercontent.com/jpwhite3/northwind-SQLite3/master/dist/northwind.db).
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="nodejs" label="NodeJS">
|
||||
@ -298,7 +297,7 @@ import * as fs from 'fs';
|
||||
XLSX.set_fs(fs);
|
||||
|
||||
/* Initialize database */
|
||||
var db = Database("Northwind_large.sqlite");
|
||||
var db = Database("northwind.db");
|
||||
|
||||
/* Create new workbook */
|
||||
var wb = XLSX.utils.book_new();
|
||||
@ -348,7 +347,7 @@ import * as fs from 'fs';
|
||||
XLSX.set_fs(fs);
|
||||
|
||||
/* Initialize database */
|
||||
var db = Database.open("Northwind_large.sqlite");
|
||||
var db = Database.open("northwind.db");
|
||||
|
||||
/* Create new workbook */
|
||||
var wb = XLSX.utils.book_new();
|
||||
@ -375,6 +374,51 @@ XLSX.writeFile(wb, "bun.xlsx");
|
||||
|
||||
3) Run `bun bun.mjs` and open `bun.xlsx`
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="deno" label="Deno">
|
||||
|
||||
[`sqlite` library](https://deno.land/x/sqlite/) returns raw arrays of arrays.
|
||||
|
||||
1) Save the following to `deno.ts`:
|
||||
|
||||
```ts title="deno.ts"
|
||||
/* Load SQLite3 connector library */
|
||||
import { DB } from "https://deno.land/x/sqlite/mod.ts";
|
||||
|
||||
/* Load SheetJS library */
|
||||
// @deno-types="https://cdn.sheetjs.com/xlsx-latest/package/types/index.d.ts"
|
||||
import * as XLSX from 'https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs';
|
||||
|
||||
/* Initialize database */
|
||||
var db = new DB("northwind.db");
|
||||
|
||||
/* Create new workbook */
|
||||
var wb = XLSX.utils.book_new();
|
||||
|
||||
/* Get list of table names */
|
||||
var sql = db.prepareQuery("SELECT name FROM sqlite_master WHERE type='table'");
|
||||
var result = sql.all();
|
||||
/* Loop across each name */
|
||||
result.forEach(function(row) {
|
||||
/* Get first 100K rows */
|
||||
var query = db.prepareQuery("SELECT * FROM '" + row[0] + "' LIMIT 100000")
|
||||
var aoa = query.all();
|
||||
if(aoa.length > 0) {
|
||||
/* Create array of arrays */
|
||||
var data = [query.columns().map(x => x.name)].concat(aoa);
|
||||
/* Create Worksheet from the aoa */
|
||||
var ws = XLSX.utils.aoa_to_sheet(data, {dense: true});
|
||||
/* Add to Workbook */
|
||||
XLSX.utils.book_append_sheet(wb, ws, row[0]);
|
||||
}
|
||||
});
|
||||
|
||||
/* Write File */
|
||||
XLSX.writeFile(wb, "deno.xlsx");
|
||||
```
|
||||
|
||||
3) Run `deno run --allow-read --allow-write deno.ts` and open `deno.xlsx`
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
@ -80,7 +80,7 @@ onMount(async() => {
|
||||
// highlight-start
|
||||
pres = utils.sheet_to_json(ws); // generate objects and update state
|
||||
// highlight-end
|
||||
})
|
||||
});
|
||||
|
||||
/* get state data and export to XLSX */
|
||||
function exportFile() {
|
||||
@ -131,7 +131,7 @@ onMount(async() => {
|
||||
// highlight-start
|
||||
html = utils.sheet_to_html(ws); // generate HTML and update state
|
||||
// highlight-end
|
||||
})
|
||||
});
|
||||
|
||||
/* get state data and export to XLSX */
|
||||
function exportFile() {
|
||||
|
@ -311,7 +311,7 @@ import * as fs from 'fs';
|
||||
set_fs(fs);
|
||||
|
||||
var wb = XLSX.readFile("sheetjs.numbers");
|
||||
XLSX.writeFile(wb, "sheetjs.xls");
|
||||
XLSX.writeFile(wb, "sheetjs.xlsx");
|
||||
```
|
||||
|
||||
### Deno
|
||||
@ -327,6 +327,19 @@ const wb = XLSX.readFile("sheetjs.numbers");
|
||||
XLSX.writeFile(wb, "sheetjs.xlsx");
|
||||
```
|
||||
|
||||
### Bun
|
||||
|
||||
Bun requires the `fs` module:
|
||||
|
||||
```js
|
||||
import * as XLSX from 'xlsx';
|
||||
import * as fs from 'fs';
|
||||
XLSX.set_fs(fs);
|
||||
|
||||
var wb = XLSX.readFile("sheetjs.numbers");
|
||||
XLSX.writeFile(wb, "sheetjs.xlsx");
|
||||
```
|
||||
|
||||
### Apps
|
||||
|
||||
Desktop and mobile apps have their own specific APIs covered in separate demos:
|
||||
|
@ -78,12 +78,12 @@ function Table2XLSX(props) {
|
||||
|
||||
/* Callback invoked when the button is clicked */
|
||||
const xport = React.useCallback(async () => {
|
||||
/* Create worksheet from HTML DOM TABLE */
|
||||
const table = document.getElementById("Table2XLSX");
|
||||
const wb = XLSX.utils.table_to_book(table);
|
||||
/* Create worksheet from HTML DOM TABLE */
|
||||
const table = document.getElementById("Table2XLSX");
|
||||
const wb = XLSX.utils.table_to_book(table);
|
||||
|
||||
/* Export to file (start a download) */
|
||||
XLSX.writeFile(wb, "SheetJSTable.xlsx");
|
||||
/* Export to file (start a download) */
|
||||
XLSX.writeFile(wb, "SheetJSTable.xlsx");
|
||||
});
|
||||
|
||||
return (<>
|
||||
|
Loading…
Reference in New Issue
Block a user