我正在使用exceljs npm软件包格式化excelsheet,但是当数据太大时,我无法在单元格内进行textwrap。导出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) {
}
答案 0 :(得分:0)
如果只想换行,可以使用cell的'alignment'属性。
worksheet.getCell('D1').alignment = { wrapText: true };