You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import * as XLSX from "xlsx";
// create a new workbook and worksheet
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.aoa_to_sheet([[]]);
// define the headers and data
const headers: string[] = ["Header1", "Header2", "Header3"];
const data: string[][] = [
["Data1", "Data2", "Data3"],
["Data4", "Data5", "Data6"],
["Data7", "Data8", "Data9"],
];
// add the headers to the worksheet
XLSX.utils.sheet_add_aoa(
worksheet,
headers.map((header) => [header]),
{ origin: "A1" }
);
// add the data to the worksheet
XLSX.utils.sheet_add_aoa(worksheet, data, { origin: "B1" });
// add the worksheet to the workbook
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
// write the workbook to a file
XLSX.writeFile(workbook, "output.xlsx");
Hi is it possible to write the output to the excel file as shown below? Have the headers in one column (A1) and data in another (B1).
Rather than the normal behavior as shown below
The text was updated successfully, but these errors were encountered: