Angular XLSX-在同一XL文件中创建多个纸
我需要下载带有3张纸(说明,填充数据,dataOptions)
指令表的Excel文件的标题,其中包含大胆文本:“指令” 例如: - 1.请仔细填写选项 2。从“ Sheet-Data选项”等复制选定的下拉值。
数据填充表将用于填写值
数据选项表可能会保留下拉选项
Ex:Indian, 英国 ...
在TS中,我添加了这样的添加,并且从以下代码中,它生成了2张带有说明,数据填充标头的表格。但是,将诸如大胆,单元格宽度之类的样式提供给其他方法?
arr: Array<any>;
arr2: Array<any>;
textData: any = 'this is text message.....';
constructor() {
this.arr = [
{ name: 'Moran', role: 'back' },
{ name: 'Alain', role: 'front' },
{ name: 'Tony', role: 'back' },
{ name: 'Mike', role: 'back' },
{ name: 'Abo', role: 'back' },
{ name: 'Toni', role: 'back' },
];
this.arr2 = [
{ instructions: `1. Use the "Template" sheet to fill.` },
{ instructions: `2. Use the "Template" sheet to fill 2.` }
];
}
exportToExcel($event) {
const fileName = 'test.xlsx';
const wb: XLSX.WorkBook = XLSX.utils.book_new();
var ws1 = XLSX.utils.json_to_sheet(this.arr2);
XLSX.utils.book_append_sheet(wb, ws1, 'test1');
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.arr);
XLSX.utils.book_append_sheet(wb, ws, 'test');
XLSX.writeFile(wb, fileName);
}
i have a requirement of download the excel file with 3 sheets(instructions, fill data, dataoptions)
instruction sheet will have a header with bold text: "Instructions"
ex: - 1.please fill the options carefully
2. Copy the select dropdown values from 'sheet-data options'....etc in first sheet.
data fill sheet will be for filling the values
data options sheet will be likely to hold dropdown options
ex: indian,
british
...etc
in the ts, i added like this and from the below code, it generating the 2 sheets with instructions, data fill header.. but provide the styles like bold, cell width to some more how to handle with this ?
arr: Array<any>;
arr2: Array<any>;
textData: any = 'this is text message.....';
constructor() {
this.arr = [
{ name: 'Moran', role: 'back' },
{ name: 'Alain', role: 'front' },
{ name: 'Tony', role: 'back' },
{ name: 'Mike', role: 'back' },
{ name: 'Abo', role: 'back' },
{ name: 'Toni', role: 'back' },
];
this.arr2 = [
{ instructions: `1. Use the "Template" sheet to fill.` },
{ instructions: `2. Use the "Template" sheet to fill 2.` }
];
}
exportToExcel($event) {
const fileName = 'test.xlsx';
const wb: XLSX.WorkBook = XLSX.utils.book_new();
var ws1 = XLSX.utils.json_to_sheet(this.arr2);
XLSX.utils.book_append_sheet(wb, ws1, 'test1');
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.arr);
XLSX.utils.book_append_sheet(wb, ws, 'test');
XLSX.writeFile(wb, fileName);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这将帮助您实现目标。 多个工作表
I think this will help you to achieve your goal. Multiple WorkSheets
这就是我能够在同一工作簿中添加多张纸的方式。
This is how I was able to add multiple sheet to the same workbook.