Excel Import/Export

You will need to install @rowsncolumns/export npm package to add support for reading and writing excel file. Values that are preserved are

  1. Cell values
  2. Datatypes
  3. Fill
  4. Border
  5. Frozen columns and rows
  6. Merge cells

Import from Excel

import { parse, download } from '@rowsncolumns/export'
import Spreadsheet, { Sheet, defaultSheets } from "@rowsncolumns/spreadsheet";
const App = () => {
const [ sheets, setSheets] = useState(defaultSheets)
const handleFileSelect = (e) => {
const getSheets = async (file) => {
const newSheets = await parse({ file })
setSheets(newSheets.sheets)
}
getSheets(e.target.files[0])
}
return (
<>
<input type="file" onChange={handleFileSelect} />
<Spreadsheet
sheets={sheets}
onChange={setSheets}
/>
</>
)
}

Export to excel

const App = () => {
const [ sheets, setSheets] = useState(defaultSheets)
const handleExport = useCallback((sheets) => {
download({ sheets })
}, [])
return (
<>
<button onClick={() => handleExport({ sheets })}>Export to excel</button>
<Spreadsheet
sheets={sheets}
onChange={setSheets}
/>
</>
);
};

Demo

https://rowsncolumns.github.io/grid/?path=/story/spreadsheet--import