diff --git a/src/components/Data.jsx b/src/components/Data.jsx index e467f00..d067a63 100644 --- a/src/components/Data.jsx +++ b/src/components/Data.jsx @@ -44,7 +44,7 @@ export const TableExportBtn = (props) => { }), {}) : {}) }), {}); const flatCols = props.columns.flatMap((v, k) => - v.children ? v.children.map((vc, ci) => ({ ...vc, title: `${v?.titleX || v.title}` + (vc?.titleX ? `,${vc.titleX}` : (ci || '')) })) : v + v.children ? v.children.map((vc, ci) => ({ ...vc, title: `${v?.titleX || v.title}` + (vc?.titleX ? `,${vc.titleX}` : (ci || '')) })) : {...v, title: `${v?.titleX || v.title}`} ); // .filter((c) => c.dataIndex) // !['string', 'number'].includes(typeof vc.title) ? `${v?.titleX || v.title}` : `${v?.titleX || v.title}-${vc.title || ''}` @@ -74,7 +74,7 @@ export const TableExportBtn = (props) => { }, {}); return itemMapped; }); - const ws = utils.json_to_sheet([summaryRow, ...data], { header: columnsMap.filter((r) => r.dataIndex).map((r) => r.title) }); + const ws = utils.json_to_sheet([].concat(isEmpty(summaryRow) ? [] : [summaryRow], data), { header: columnsMap.filter((r) => r.dataIndex).map((r) => r.title) }); const wb = utils.book_new(); utils.book_append_sheet(wb, ws, 'sheet'); writeFile(wb, `${output_name}.xlsx`);