按照堆栈和stackblitz上的这个问题,如果分页没有显示所有数据,那么material似乎不会完全导出到excel。
因此,我将将数组作为一个整体导出,但问题是主字段名显示的是索引而不是名称:
因此,与其:
exportTable()
{
//let data = Object.values(this.dataSource);
const ws: xlsx.WorkSheet=xlsx.utils.table_to_sheet(data);
const wb: xlsx.WorkBook = xlsx.utils.book_new();
xlsx.utils.book_append_sheet(wb, ws, 'All Ind. Searched Data Export');
/* save to file */
xlsx.writeFile(wb, 'ExportAllData_Ind.xlsx');
}我改为:
exportTable()
{
let data = Object.values(this.dataSource);
const ws: xlsx.WorkSheet=xlsx.utils.json_to_sheet(data);
const wb: xlsx.WorkBook = xlsx.utils.book_new();
xlsx.utils.book_append_sheet(wb, ws, 'All Ind. Searched Data Export');
/* save to file */
xlsx.writeFile(wb, 'ExportAllData_Ind.xlsx');
}问题是导出的excel正在将字段名设置为索引,然后在末尾添加实字段名:

我知道这与数组有关,但是如何仅用字段名部分导出数组。
发布于 2018-12-24 07:07:04
好的,我找到了我自己的解决方案,直到提取角材料数据表的问题得到了解决,因为它只是在提取活动分页表,而不是所有表。我只是用了传统的方法:
exportTable()
{
let newArray:any[]=[];
let data = Object.values(this.allsearched);
Object.keys(data).forEach((key, index)=>{
newArray.push({
'Ind. ID': data[key].individual_id,
'HH ID': data[key].hh_id,
'Name(en)': data[key].ind_first_name_en+' '+data[key].ind_last_name_en,
'Name(ar)': data[key].ind_first_name_ar+' '+data[key].ind_last_name_ar,
'UID': data[key].uId,
'Gender': data[key].ind_gender,
'D.O.B': data[key].dob,
'Head Of HH': data[key].head_of_hh,
'Phone Number': data[key].phone,
'Status': data[key].ind_status,
'User ID': data[key].user_id
})
})
const ws: xlsx.WorkSheet=xlsx.utils.json_to_sheet(newArray);
const wb: xlsx.WorkBook = xlsx.utils.book_new();
xlsx.utils.book_append_sheet(wb, ws, 'All Ind. Searched Data Export');
/* save to file */
xlsx.writeFile(wb, 'ExportAllData_Ind.xlsx');
}https://stackoverflow.com/questions/53909999
复制相似问题