Browse Source

fix(nocodb): provide header in XLSX.utils.json_to_sheet

pull/4581/head
Wing-Kam Wong 2 years ago
parent
commit
a5f05eea3f
  1. 5
      packages/nocodb/src/lib/meta/api/dataApis/helpers.ts
  2. 4
      packages/nocodb/src/lib/meta/api/publicApis/publicDataExportApis.ts

5
packages/nocodb/src/lib/meta/api/dataApis/helpers.ts

@ -58,7 +58,10 @@ export async function extractXlsxData(view: View, req: Request) {
}); });
const { offset, dbRows, elapsed } = await getDbRows(baseModel, view, req); const { offset, dbRows, elapsed } = await getDbRows(baseModel, view, req);
const data = XLSX.utils.json_to_sheet(dbRows);
const fields = req.query.fields as string[];
const data = XLSX.utils.json_to_sheet(dbRows, { header: fields });
return { offset, dbRows, elapsed, data }; return { offset, dbRows, elapsed, data };
} }

4
packages/nocodb/src/lib/meta/api/publicApis/publicDataExportApis.ts

@ -32,7 +32,9 @@ async function exportExcel(req: Request, res: Response) {
const { offset, dbRows, elapsed } = await getDbRows(model, view, req); const { offset, dbRows, elapsed } = await getDbRows(model, view, req);
const data = XLSX.utils.json_to_sheet(dbRows); const fields = req.query.fields as string[];
const data = XLSX.utils.json_to_sheet(dbRows, { header: fields });
const wb = XLSX.utils.book_new(); const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, data, view.title); XLSX.utils.book_append_sheet(wb, data, view.title);
const buf = XLSX.write(wb, { type: 'base64', bookType: 'xlsx' }); const buf = XLSX.write(wb, { type: 'base64', bookType: 'xlsx' });

Loading…
Cancel
Save