How To generate an Excel File

Use the ExcelFile and CsvFile class. an ExcelFile instance represents an entire Excel file and a CsvFile instance represents a sheet of the Excel File..

// 1. Create blank Excel File
var excel = new ExcelFile();

// 2. Create the first sheet using the CsvFile class
var sheet1 = new CsvFile();

// 3. Add lines to the sheet
sheet1.writeLine(["id", "name", "email"]);
sheet1.writeLine([12", "John", "john@gmail.com]);

// 4. Create a second sheet and add some lines
var sheet2 = new CsvFile();
sheet2.writeLine(["id", "note", "date"]);
sheet2.writeLine(["2", "This is a note", Format.date(Date.now())]);

// 5. Add the 2 sheets to the excel file
excel.addSheet(sheet1.getContent());
excel.addSheet(sheet2.getContent());

// 6. Download the excel file
excel.download("export.xlsx");