Use the @rowsncolumns/toolkit package to read, write and download Excel files from SheetData object
Import from Excel
Converts an excel file to sheets, sheetData which can be used in the CanvasGrid.
Note: To generate patches, undo/redo when an excel file is uploaded, use onInsertFile function from useSpreadsheetStatehook
import { createRowDataFromExcelFile } from "@rowsncolumns/toolkit";
const App = () => {
const { onInsertFile } = useSpreadsheetState()
const handleChange = async (e) => {
const file = e.target.files[0]
// Option 1: To let useSpreadsheetState hook to manage collab, undo/redo state
onInsertFile(file)
// Option 2: To manually update state
const { sheets, sheetData, tables } = await createRowDataFromExcelFile(file)
onChange(sheets)
onChangSheetData(sheetData)
onChangeTables(tables)
// Call calculateNow to trigger a full-recalc if you are using
// useSpreadsheetState hook
}
return (
<div>
<input type="file" onChange={handleChange} />
</div>
)
}
Importing large excel files
createRowDataFromExcelFile when run on the main thread can block UI interactions which is why you can createExcelImporterthat outputs each sheet in an async iterator