45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import * as XLSX from "xlsx";
|
|
|
|
export const standardTemplate = async () => {
|
|
/**
|
|
* Creates the standard Template for bulk orders in
|
|
*/
|
|
|
|
const headers = [
|
|
[
|
|
"CustomerArticleNumber",
|
|
"CustomerOrderNumber",
|
|
"CustomerLineNumber",
|
|
"CustomerRealeaseNumber",
|
|
"Quantity",
|
|
"DeliveryDate",
|
|
"CustomerID",
|
|
"Remark",
|
|
// "InvoiceID",
|
|
],
|
|
];
|
|
|
|
// create a new workbook
|
|
const wb = XLSX.utils.book_new();
|
|
const ws = XLSX.utils.aoa_to_sheet(headers);
|
|
//const ws2 = XLSX.utils.aoa_to_sheet(headers2);
|
|
|
|
const columnWidths = headers[0].map((header) => ({
|
|
width: header.length + 2,
|
|
}));
|
|
|
|
ws["!cols"] = columnWidths;
|
|
|
|
// append the worksheet to the workbook
|
|
XLSX.utils.book_append_sheet(wb, ws, `Sheet1`);
|
|
//XLSX.utils.book_append_sheet(wb, ws2, `Sheet2`);
|
|
|
|
// Write the excel file and trigger the download'
|
|
XLSX.writeFile(wb, "BulkOrdersTemplate");
|
|
|
|
// Write the workbook to a buffer and return it
|
|
const excelBuffer = XLSX.write(wb, { bookType: "xlsx", type: "buffer" });
|
|
|
|
return excelBuffer;
|
|
};
|