Import and export from XLSX files
This examples shows the JSS Parser and JSS Render premium extensions and required specific licenses. The extensions helps to convert a XLSX file into JSS and export a JSS spreadsheet to a XLSX file. Both extensions require a specific license.
The best results would be in combination with Jspreadsheet Version 8 with Formula Pro
Using CDN
<html>
<script src="https://jspreadsheet.com/v7/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v7/jspreadsheet.css" type="text/css" />
<script src="https://cdn.jsdelivr.net/npm/jszip@3.6.0/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/parser@1.1.1/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/render@1.2.0/dist/index.min.js"></script>
<div id="spreadsheet"></div>
<script>
// Set your license
jspreadsheet.license = 'ZDRmMjE0NmJkNjRhMzM4NDQzMjJhNDVhYmJmOGQ1ZjI2MDA4MDU1MmY5ZDBmYTE2MjU3OTU3ZjAwYjE1ZmZjODZmMDg2NDA3MGVlNDA2NzhjNDA3NGIyZjk5MjhmNzIxMjNhODNhOWQxYmM0MWM0MWY5ZTJkM2M2ZGQ5ZmVlYTAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNeU16STVOamc0TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==';
//Set extensions
jspreadsheet.setExtensions({ parser, render });
// Create the spreadsheet from a local file
let load = function(e) {
// Destroy any existing JSS
jspreadsheet.destroy(document.getElementById('spreadsheet'));
// Parse XLSX file and create a new spreadsheet
jspreadsheet.parser({
file: e.target.files[0],
onload: function(config) {
jspreadsheet(document.getElementById('spreadsheet'), config.worksheets);
},
});
}
let download = function() {
// Render receives the DOM Element
jspreadsheet.render(document.getElementById('spreadsheet'));
}
</script>
</html>
Using NPM
import React, { useRef, useEffect } from "react";
import jspreadsheet from "jspreadsheet-pro";
import parser from "@jspreadsheet/parser";
import "jspreadsheet-pro/dist/jspreadsheet.css";
import "jsuites/dist/jsuites.css";
export default function App() {
const spreadsheetRef = useRef(null);
const license = "ZDRmMjE0NmJkNjRhMzM4NDQzMjJhNDVhYmJmOGQ1ZjI2MDA4MDU1MmY5ZDBmYTE2MjU3OTU3ZjAwYjE1ZmZjODZmMDg2NDA3MGVlNDA2NzhjNDA3NGIyZjk5MjhmNzIxMjNhODNhOWQxYmM0MWM0MWY5ZTJkM2M2ZGQ5ZmVlYTAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNeU16STVOamc0TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==";
jspreadsheet.license = license;
jspreadsheet.setExtensions({ parser });
//Create the spreadsheet from a local file
let load = function (e) {
// Destroy any existing JSS
jspreadsheet.destroy(spreadsheetRef.current);
// Parse XLSX file and create a new spreadsheet
jspreadsheet.parser({
file: e.target.files[0],
onload: function (config) {
jspreadsheet(spreadsheetRef.current, config.worksheets);
}
});
};
return (
<div>
<div ref={spreadsheetRef} />
<input type="file" name="file" id="file" onChange={(e) => load(e)} />
</div>
);
}
Working Example on codesandbox
See a working data grid example with the option to import from XLSX and export to XLSX on codesandbox.