Skip to content
Convert excel file to json data
Branch: master
Clone or download
Latest commit 55c986a Mar 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example init Feb 14, 2019
js
src [fix] default border color Feb 27, 2019
wasm
.gitignore init Feb 14, 2019
Cargo.lock [dev] update dependencies versions Mar 22, 2019
Cargo.toml
README.md Update README.md Mar 6, 2019
package.json 1.0.2 Mar 22, 2019
rollup.config.js init Feb 14, 2019
yarn.lock init Feb 14, 2019

README.md

Excel2json

Excel2json is a Rust and WebAssembly-based library that allows easily converting files in Excel format to JSON files.

npm version

How to build

yarn install
// build js code
yarn build
// rebuild wasm code
// rust toolchain is required
yarn build-wasm

How to use via npm

  • install the module
yarn add excel2json-wasm
  • import the module
// worker.js
import("excel2json-wasm")
  • use the module in the app
// app.js
const worker = new Worker("worker.js");

// convert excel file to json
worker.postMessage({
    type: "convert",
    data: file_object_or_typed_array
});

worker.addEventListener("message", e => {
    if (e.data.type === "ready"){
        const data = e.data.data;
        const styles = e.data.styles;

        //json data is ready
        console.log(data, styles)
    }
});

How to use from CDN

CDN links are the following:

In case you use build system like webpack, it is advised to wrap the link to CDN source into a blob object to avoid possible breakdowns:

var url = window.URL.createObjectURL(new Blob([
    "importScripts('https://cdn.dhtmlx.com/libs/excel2json/1.0/worker.js');"
], { type: "text/javascript" }));

var worker = new Worker(url);

Output format

interface IConvertMessageData {
    uid?: string;
    data: Uint8Array | File;
    sheet?: string;
    styles?: boolean;
    wasmPath?: string;
}

interface IReadyMessageData {
    uid: string;
    data: ISheetData[];
    styles: IStyles[];
}

interface ISheetData {
    name: string;
    cols: IColumnData[];
    rows: IRowData[];
    cells: IDataCell[][];   // null for empty cell

    merged: IMergedCell[];
}

interface IMergedCell {
    from: IDataPoint;
    to: IDataPoint;
}

interface IDataPoint {
    column: number; 
    row: number;
}

interface IColumnData {
    width: number;
}

interface IRowData {
    height: number;
}

interface IDataCell{
    v: string;
    s: number:
}

interface IStyle {
    fontSize?: string;
    fontFamily?: string;

    background?: string;
    color?: string;

    fontWeight?: string;
    fontStyle?: string;
    textDecoration?: string;

    textAlign?: string;
    verticalAlign?: string;

    borderLeft?: string;
    borderTop?: string;
    borderBottom?: string;
    borderRight?: string;

    format?: string;
}

License

MIT

You can’t perform that action at this time.