Giter Site home page Giter Site logo

excel2json's Introduction

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

wasm

cargo install wasm-pack
wasm-pack build --target web

js

yarn install
yarn build

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)
    }
});

Export formulas

worker.postMessage({
    type: "convert",
    data: file_object_or_typed_array,
    formulas: true
});

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.1/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

excel2json's People

Contributors

kolosovao avatar mafanya23 avatar mkozhukh avatar stanislav-wolski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.