exceljs 在 worksheet.columns = [] array in Angular 的行中给出错误
exceljs giving an error in lines for worksheet.columns = [] array in Angular
当我创建 worksheet.columns = [] 数据时,它显示 wrong.I 正在使用 VSCode,下面有所有详细信息。
版本:1.52.1(用户设置)
提交:ea3859d4ba2f3e577a159bc91e3074c5d85c0523
日期:2020-12-16T16:34:46.910Z
电子:9.3.5
Chrome:83.0.4103.122
Node.js:12.14.1
V8:8.3.110.13-电子.0
OS: Windows_NT x64 10.0.17763
worksheet.columns = [
{ key: 'QuestionTitle', width: 20 },
{ key: 'RespondedBy', width: 25 },
{ key: 'ResponseDateTime', width: 25 },
{ key: 'Response', width: 50 },
{ key: 'Tag', width: 20 }
];
在我看来,以上是正确的。但是 VScode 告诉我这是错误的。
enter image description here
下面有完整的代码。
public exportAsExcelFile(excelData: any[], excelFileName: string, surveyTitle: string, clientDateFormat: string): void {
const workbook = new ExcelJS.Workbook();
workbook.creator = 'My-Team';
workbook.lastModifiedBy = 'SSE';
workbook.created = new Date(2021, 2, 10);
workbook.modified = new Date();
workbook.lastPrinted = new Date();
// Set workbook dates to 1904 date system
workbook.properties.date1904 = true;
const worksheet = workbook.addWorksheet('Responses');
worksheet.mergeCells('A1', 'E2');
worksheet.getCell('C1').value = surveyTitle;
worksheet.getRow(3).values = ['Question Title', 'Responded By', 'Response Date & Time', 'Responses', 'Tags Name'];
worksheet.columns = [
{ key: 'QuestionTitle', width: 20 },
{ key: 'RespondedBy', width: 25 },
{ key: 'ResponseDateTime', width: 25 },
{ key: 'Response', width: 50 },
{ key: 'Tag', width: 20 }
];
excelData.forEach(element => {
console.log("element: ", element);
if(element.ResponseDateTime != "")
{
element.ResponseDateTime = this.datepipe.transform(element.ResponseDateTime, clientDateFormat);
}
const row = worksheet.addRow(element);
//Make a boarder to data.
row.eachCell(function (cell) {
cell.border = {
top: { style: 'thin' },
left: { style: 'thin' },
bottom: { style: 'thin' },
right: { style: 'thin' }
};
})
});
workbook.xlsx.writeBuffer().then((buffer: any) => {
console.log("buffer: ", buffer);
const data: Blob = new Blob([buffer], { type: EXCEL_TYPE });
FileSaver.saveAs(data, excelFileName + EXCEL_EXTENSION);
});
}
如有任何帮助,我们将不胜感激。
这是exceljs库中的一个known bug,在打字稿中使用时,
您可以试试这个解决方法:
...
worksheet.columns = [
{ key: 'QuestionTitle', width: 20 },
{ key: 'RespondedBy', width: 25 },
{ key: 'ResponseDateTime', width: 25 },
{ key: 'Response', width: 50 },
{ key: 'Tag', width: 20 }
] as ExcelJS.Column[];
当我创建 worksheet.columns = [] 数据时,它显示 wrong.I 正在使用 VSCode,下面有所有详细信息。 版本:1.52.1(用户设置) 提交:ea3859d4ba2f3e577a159bc91e3074c5d85c0523 日期:2020-12-16T16:34:46.910Z 电子:9.3.5 Chrome:83.0.4103.122 Node.js:12.14.1 V8:8.3.110.13-电子.0 OS: Windows_NT x64 10.0.17763
worksheet.columns = [
{ key: 'QuestionTitle', width: 20 },
{ key: 'RespondedBy', width: 25 },
{ key: 'ResponseDateTime', width: 25 },
{ key: 'Response', width: 50 },
{ key: 'Tag', width: 20 }
];
在我看来,以上是正确的。但是 VScode 告诉我这是错误的。
enter image description here
下面有完整的代码。
public exportAsExcelFile(excelData: any[], excelFileName: string, surveyTitle: string, clientDateFormat: string): void {
const workbook = new ExcelJS.Workbook();
workbook.creator = 'My-Team';
workbook.lastModifiedBy = 'SSE';
workbook.created = new Date(2021, 2, 10);
workbook.modified = new Date();
workbook.lastPrinted = new Date();
// Set workbook dates to 1904 date system
workbook.properties.date1904 = true;
const worksheet = workbook.addWorksheet('Responses');
worksheet.mergeCells('A1', 'E2');
worksheet.getCell('C1').value = surveyTitle;
worksheet.getRow(3).values = ['Question Title', 'Responded By', 'Response Date & Time', 'Responses', 'Tags Name'];
worksheet.columns = [
{ key: 'QuestionTitle', width: 20 },
{ key: 'RespondedBy', width: 25 },
{ key: 'ResponseDateTime', width: 25 },
{ key: 'Response', width: 50 },
{ key: 'Tag', width: 20 }
];
excelData.forEach(element => {
console.log("element: ", element);
if(element.ResponseDateTime != "")
{
element.ResponseDateTime = this.datepipe.transform(element.ResponseDateTime, clientDateFormat);
}
const row = worksheet.addRow(element);
//Make a boarder to data.
row.eachCell(function (cell) {
cell.border = {
top: { style: 'thin' },
left: { style: 'thin' },
bottom: { style: 'thin' },
right: { style: 'thin' }
};
})
});
workbook.xlsx.writeBuffer().then((buffer: any) => {
console.log("buffer: ", buffer);
const data: Blob = new Blob([buffer], { type: EXCEL_TYPE });
FileSaver.saveAs(data, excelFileName + EXCEL_EXTENSION);
});
}
如有任何帮助,我们将不胜感激。
这是exceljs库中的一个known bug,在打字稿中使用时, 您可以试试这个解决方法:
...
worksheet.columns = [
{ key: 'QuestionTitle', width: 20 },
{ key: 'RespondedBy', width: 25 },
{ key: 'ResponseDateTime', width: 25 },
{ key: 'Response', width: 50 },
{ key: 'Tag', width: 20 }
] as ExcelJS.Column[];