Excel2json
Convert excel file to json data
Install / Use
/learn @DHTMLX/Excel2jsonREADME
Excel2json
Excel2json is a Rust and WebAssembly-based library that allows easily converting files in Excel format to JSON files.
How to build
wasm
cargo install wasm-pack
wasm-pack build
How to use via npm
- install the module
yarn add excel2json-wasm
- import and use the module
// worker.js
import {convert} "excel2json-wasm";
// convert int-array, works in sync mode
const json = convertArray(Int8Array, optional_config);
// converts file object or int-array in async mode
convert(file_object_or_typed_array, optional_config).then(json => {
// do something
});
How to use from CDN
CDN links are the following:
- https://cdn.dhtmlx.com/libs/excel2json/1.5/worker.js
- https://cdn.dhtmlx.com/libs/excel2json/1.5/module.js
- https://cdn.dhtmlx.com/libs/excel2json/1.5/excel2json_wasm_bg.wasm
You can import and use lib dynamically like
const convert = import("https://cdn.dhtmlx.com/libs/excel2json/1.5/module.js");
const blob = convert(json_data_to_export);
or use it as web worker
var url = window.URL.createObjectURL(new Blob([
"importScripts('https://cdn.dhtmlx.com/libs/excel2json/1.5/worker.js');"
], { type: "text/javascript" }));
// you need to server worker from the same domain as the main script
var worker = new Worker("./worker.js");
worker.addEventListener("message", ev => {
if (ev.data.type === "ready"){
const json = ev.data.data;
// do something
}
});
worker.postMessage({
type:"convert",
data: file_object
});
worker.addEventListener("message", e => {
if (e.data.init){
// worker is ready
}
})
if you want to load worker script from CDN and not from your domain it requires a more complicated approach, as you need to catch the moment when service inside of the worker will be fully initialized
var url = window.URL.createObjectURL(new Blob([
"importScripts('https://cdn.dhtmlx.com/libs/excel2json/1.5/worker.js');"
], { type: "text/javascript" }));
var worker = new Promise((res) => {
const x = Worker(url);
worker.addEventListener("message", ev => {
if (ev.data.type === "ready"){
const json = ev.data.data;
// do something with result
} else if (ev.data.type === "init"){
// service is ready
res(x);
}
});
});
worker.then(x => x.postMessage({
type:"convert",
data: file_object
}));
Export formulas
const json = convert(data, { formulas:true });
or
worker.postMessage({
type: "convert",
data: file_object_or_typed_array,
formulas: true
});
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;
align?: string;
verticalAlign?: string;
borderLeft?: string;
borderTop?: string;
borderBottom?: string;
borderRight?: string;
format?: string;
}
License
MIT
Related Skills
node-connect
350.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
