this.exportAsExcelFile(this.result, 'Report');
// this.result: it is json object
// 'Report': file name
我有| (管)分隔的字符串。它打印在一行see image for more info
答案 0 :(得分:1)
最后我得到了回答。 字符串应该是这样的:
str = "line1 \r\n line2 \r\n line3";
这个字符串在E列和第2行中,这就是为什么我写了它像
this.wrapAndCenterCell(worksheet['E2']);
见下面的功能:
public exportAsExcelFile(json: any[], excelFileName: string): void {
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
this.wrapAndCenterCell(worksheet['E2']); //
const workbook: XLSX.WorkBook ={Sheets:{'data':worksheet},SheetNames:
['data'] };
const excelBuffer: any = XLSXStyle.write(workbook, { bookType: 'xlsx',
type:
'buffer' });
this.saveAsExcelFile(excelBuffer, excelFileName);
}