I'm implementing xlsx libray using xlsx-js-style
which is forked from sheetjs
and file-saver
for saving the xlsx file. Export to excel functionality works fine in local development but when deployed to production e.g vercel the downloaded excel file cant open:
Error when opening SS:
Code Snippet SS:
import { utils, WorkSheet, write } from "xlsx-js-style";
import { saveAs } from "file-saver";
const exportToCSV = () => {
// Initialize new Book
const wb = utils.book_new();
// Iterate SObject and create new sheet per SObject.
Object.keys(sObjectsWithDetailsData).forEach((key) => {
if (!sObjectsWithDetailsData[key]) return;
// Filter Rows Data
const rows = sObjectsWithDetailsData[key]?.map((row) => ({
"R/O": row.updateable ? "✓" : "☐",
R: !row.nillable ? "*" : "",
label: row.label ?? "",
name: row.name ?? "",
fieldDescription: row.fieldDescription ?? "",
inlineHelpText: row.inlineHelpText ?? "",
custom: row.custom ?? false,
externalId: row.externalId ?? false,
type: row.type ?? "",
calculatedFormula: row.calculatedFormula ?? "",
picklistValues:
row.picklistValues
?.map((picklist) => picklist.label)
.join("\n") ?? "",
}));
const ws = utils.json_to_sheet(rows ?? []);
// Modify Header Names
utils.sheet_add_aoa(
ws,
[
[
"R/O",
"M",
"Label",
"API Name",
"Description",
"HelpText",
"Is Custom",
"Is External ID",
"Type",
"Formula Text",
"Picklist Values",
],
],
{
origin: "A1",
}
);
utils.book_append_sheet(wb, ws, key);
});
// Execute export
const wbout = write(wb, { bookType: "xlsx", type: "binary" });
saveAs(
new Blob([s2ab(wbout)], { type: "application/octet-stream" }),
"test.xlsx"
);
};