docs.sheetjs.com/docz/docs/03-demos/06-data/03-indexeddb.md

32 lines
828 B
Markdown
Raw Normal View History

2023-02-24 07:46:48 +00:00
---
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);
```