Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 views
in Technique[技术] by (71.8m points)

angular8 - export to excel function for array within array in Angular 8 in p-table

I am using p- table in my component and trying to use the export to excel function in p-table. my data looks like this...

[{
LanguageCountryCode: "enUSA",
Messages:
[
{DateTime: "2021-01-03T18:52:58.0003345", Log4NetLevel: "INFO", UniqueID: "DC85D61C-5154-496C-B94F-10300B273706", Message: "received filter request using HTTP GET"},
{DateTime: "2021-01-03T18:52:58.0003346", Log4NetLevel: "INFO", UniqueID: "2C16E2AE-C5F7-4C0A-82C2-CB8CB3DFD249", Message: "starting request"},
{DateTime: "2021-01-03T18:52:58.0003347", Log4NetLevel: "DEBUG", UniqueID: "5274B06E-2B92-407A-9733-3ECC7EC3A7EC", Message: "deliverable id is 132466"},
{DateTime: "2021-01-03T18:53:01.0003348", Log4NetLevel: "INFO", UniqueID: "F6B3A99E-C833-4BF9-85C7-812280819D3A", Message: "finished request. filtered 154 MOIDs"}
]
PartNumber: "partnumber"
RequesterIPAddress: "204.156.180.47"
SessionID: "152BE302-02CF-4709-A5D8-FE2581619171"
VIN: "1FTEW1CP7MFA33521"
VariantID: "7318"
},
{
LanguageCountryCode: "enUSA"
Messages:[
{DateTime: "2021-01-03T19:05:35.0003349", Log4NetLevel: "INFO", UniqueID: "F9BDD9B8-539B-4030-8BAB-1BB920F24630", Message: "received filter request using HTTP GET"},
{DateTime: "2021-01-03T19:05:35.0003350", Log4NetLevel: "INFO", UniqueID: "38B28EDF-F256-437B-806F-5B03E0C4DA88", Message: "starting request"},
{DateTime: "2021-01-03T19:05:35.0003351", Log4NetLevel: "DEBUG", UniqueID: "C1BF83B7-D908-4DB9-8AF4-5A811F5A83C9", Message: "deliverable id is 132468"},
{DateTime: "2021-01-03T19:05:39.0003352", Log4NetLevel: "INFO", UniqueID: "113D0403-B5EC-463D-972D-E1364CA58B44", Message: "finished request. filtered 119 MOIDs"}
]
PartNumber: "partnumber",
RequesterIPAddress: "204.156.181.42",
SessionID: "222465D0-B242-4512-91B3-0194BE410AD8",
VIN: "1FTFW1E85MFA25931",
VariantID: "7320"
}]

i went through this

https://primefaces.org/primeng/showcase/#/table/export

and using

exportExcel() {
        import("xlsx").then(xlsx => {
            const worksheet = xlsx.utils.json_to_sheet(this.products);
            const workbook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
            const excelBuffer: any = xlsx.write(workbook, { bookType: 'xlsx', type: 'array' });
            this.saveAsExcelFile(excelBuffer, "products");
        });
    }

    saveAsExcelFile(buffer: any, fileName: string): void {
        import("file-saver").then(FileSaver => {
            let EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
            let EXCEL_EXTENSION = '.xlsx';
            const data: Blob = new Blob([buffer], {
                type: EXCEL_TYPE
            });
            FileSaver.saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION);
        });
    }

now my excel looks like this with out messages how to get the messages into excel? thanks excel

question from:https://stackoverflow.com/questions/65850539/export-to-excel-function-for-array-within-array-in-angular-8-in-p-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...