Skip to content

Instantly share code, notes, and snippets.

@kno3comma14
Created March 13, 2025 09:33
Show Gist options
  • Save kno3comma14/6177e2ddbdc2bf39c2e705171c085096 to your computer and use it in GitHub Desktop.
Save kno3comma14/6177e2ddbdc2bf39c2e705171c085096 to your computer and use it in GitHub Desktop.
Hint to create an excel
import { Injectable } from '@nestjs/common';
import * as ExcelJS from "exceljs";
@Injectable()
export class AppService {
getHello(): string {
let wb = new ExcelJS.Workbook();
let ws = wb.addWorksheet("sample_worksheet");
ws.columns = [
{ header: 'Id', key: 'id', width: 10 },
{ header: 'Name', key: 'name', width: 25}
];
ws.addRows([[1, "Bla1"], [2, "Bla2"]]);
const filename = 'output.xlsx';
wb.xlsx.writeFile(filename).then(() => {
console.log(`Congrats! File ${filename} has beed created succesfully!`);
}).catch((error) => {
console.error('Error creating file: ', error);
})
return 'Hello World!';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment