To export one worksheet to an Excel file, instead of the entire workbook of a SpreadJS instance, developers need to create a temporary workbook that will only store the worksheet that is needed to be exported. Then they can save the temporary workbook as an Excel file, only containing the one worksheet.
Steps to Complete:
1. Save and load worksheet’s json to a temporary workbook
2. Save the temporary workbook as an Excel file
Step 1: Send the worksheet’s json to a temporary workbook
SpreadJS’s API library has a toJSON method that will save the worksheet object to a JSON string. Once the worksheet is a JSON string, create an empty, temporary workbook instance to load the JSON data to using the fromJSON method.
In this example we are exporting the active sheet of the current SpreadJS instance.
Step 2: Save the temporary workbooks JSON to Excel file
After applying the code logic shared here only the activesheet from within the workbook will be exported:
Here is a link to a live sample: https://codesandbox.io/s/sjs-js-export-active-worksheet-only-m00nv?file=/index.html