我正在使用 exceljs npm 包来格式化 excelsheet 但是当数据太大时,我无法在单元格内进行文本换行。导出 excel 时,我的描述单元格包含大量数据,看起来文本与下一个单元格重叠。
try {
var workbook = new excel.Workbook();
var worksheet = workbook.addWorksheet('ABC');
worksheet.columns = [
{ header: 'ABC', key: 'ABC', width: 15 },
{ header: 'Description', key: 'Description', width: 20 },
{ header: 'Comments', key: 'Comments', width: 20 }
];
// setStyleToHeader(worksheet);
worksheet.getRow(1).font = { name: 'Calibri', family: 4, size: 12, bold: true };
worksheet.getRow(1).border = {
top: { style: 'thin' },
left: { style: 'thin' },
bottom: { style: 'thin' },
right: { style: 'thin' }
};
new sql.ConnectionPool(dbconfig).connect().then(pool => {
return pool.request()
.execute('sp_getAll_data')
}).then(result => {
debugger;
let rows = result.recordset;
for (var i = 0; i < rows.length; i++) {
worksheet.addRow({
ABC: rows[i].ABC,
Description: rows[i].Description ,
Comments: rows[i].Comments
});
}
sql.close();
workbook.xlsx.write(res);
debugger;
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader("Content-Disposition", "attachment; filename=" + "ABC.xlsx");
res.end(result, 'binary');
res.status(200).json();
}).catch(err => {
// res.status(500).send({ message: "${err}", err })
// sql.close();
});
} catch (e) {
}