Created
March 13, 2025 09:33
-
-
Save kno3comma14/6177e2ddbdc2bf39c2e705171c085096 to your computer and use it in GitHub Desktop.
Hint to create an excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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