forked from sheetjs/docs.sheetjs.com
32 lines
828 B
Markdown
32 lines
828 B
Markdown
|
---
|
||
|
title: IndexedDB API
|
||
|
pagination_prev: demos/grid
|
||
|
pagination_next: demos/worker
|
||
|
sidebar_custom_props:
|
||
|
type: web
|
||
|
---
|
||
|
|
||
|
:::warning
|
||
|
|
||
|
IndexedDB is a very low-level API. It is strongly recommended to use a wrapper
|
||
|
library or [WebSQL](/docs/demos/data/websql) in production applications.
|
||
|
|
||
|
:::
|
||
|
|
||
|
`localForage` is a IndexedDB wrapper that presents an async Storage interface.
|
||
|
|
||
|
Arrays of objects can be stored using `JSON.stringify` using row index as key:
|
||
|
|
||
|
```js
|
||
|
const aoo = XLSX.utils.sheet_to_json(ws);
|
||
|
for(var i = 0; i < aoo.length; ++i) await localForage.setItem(i, JSON.stringify(aoo[i]));
|
||
|
```
|
||
|
|
||
|
Recovering the array of objects is possible by using `JSON.parse`:
|
||
|
|
||
|
```js
|
||
|
const aoo = [];
|
||
|
for(var i = 0; i < localForage.length; ++i) aoo.push(JSON.parse(await localForage.getItem(i)));
|
||
|
const wb = XLSX.utils.json_to_sheet(aoo);
|
||
|
```
|