2024-06-16 14:31:57 +02:00
|
|
|
# ods-xlsx
|
2024-06-14 16:57:20 +02:00
|
|
|
|
2024-06-16 14:31:57 +02:00
|
|
|
Small lib to parse/understand .ods and .xsls files in the browser
|
2024-06-14 16:57:20 +02:00
|
|
|
|
|
|
|
|
|
2024-06-16 14:31:57 +02:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
### Install
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
npm i github:DavidBruant/ods-xlsx#v0.2.0
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
|
|
|
|
#### Basic
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
import {getTableRawContentFromFile, tableRawContentToObjects} from './main.js'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {File} file - a file like the ones you get from an <input type=file>
|
|
|
|
|
* @return {Promise<any[]>}
|
|
|
|
|
*/
|
|
|
|
|
async function getFileData(file){
|
2024-06-16 14:58:03 +02:00
|
|
|
return getTableRawContentFromFile(file).then(tableRawContentToObjects)
|
2024-06-16 14:31:57 +02:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The return value is an array of objects where
|
|
|
|
|
the **keys** are the column names in the first row and
|
|
|
|
|
the **values** are automatically converted from the .ods or .xlsx files (which type numbers, strings, booleans and dates)
|
|
|
|
|
to the appropriate JavaScript value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### Low-level
|
|
|
|
|
|
|
|
|
|
`getTableRawContentFromFile` returns a `Promise` for an array of array of `{value, type}` objects where:
|
|
|
|
|
- `value` is a string or `undefined` or `null` and
|
|
|
|
|
- `type` is a type defined in the .ods or .xlsx standards
|
|
|
|
|
|
|
|
|
|
See the `convertCellValue` function in the source code for an example of how to handle the `type` value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`tableRawContentToObjects` performs a conversion on values and also removes empty rows
|
|
|
|
|
|
|
|
|
|
### Demo
|
|
|
|
|
|
|
|
|
|
https://davidbruant.github.io/ods-xlsx/
|
2024-06-14 16:57:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## Local dev
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
npm install
|
|
|
|
|
npm run dev
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Expectations and licence
|
|
|
|
|
|
2024-06-16 14:31:57 +02:00
|
|
|
I hope to be credited for the work on this repo
|
2024-06-14 16:57:20 +02:00
|
|
|
|
|
|
|
|
Everything written by me and contributors to this repo is licenced under **CC0 1.0 (Public Domain)**
|
|
|
|
|
|
|
|
|
|
|
2024-06-16 14:31:57 +02:00
|
|
|
## Dependencies
|
2024-06-14 16:57:20 +02:00
|
|
|
|
2024-06-16 14:31:57 +02:00
|
|
|
Svelte and rollup are **MIT**-licence
|