Files
lstV2/server/services/logistics/controller/dm/forecast/createTemplate.ts

35 lines
982 B
TypeScript

import * as XLSX from "xlsx";
export const standardForCastTemplate = async () => {
/**
* Creates the standard Template for bulk orders in
*/
const headers = [
["CustomerArticleNumber", "Quantity", "RequirementDate", "CustomerID"],
];
// 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, "BulkForecastTemplate");
// Write the workbook to a buffer and return it
const excelBuffer = XLSX.write(wb, { bookType: "xlsx", type: "buffer" });
return excelBuffer;
};