|
|
@ -28,16 +28,26 @@ async function exportExcel(req: Request, res: Response) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const model = await view.getModelWithInfo(); |
|
|
|
const model = await view.getModelWithInfo(); |
|
|
|
|
|
|
|
|
|
|
|
await view.getColumns(); |
|
|
|
await view.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const { offset, dbRows, elapsed } = await getDbRows(model, view, req); |
|
|
|
const { offset, dbRows, elapsed } = await getDbRows(model, view, req); |
|
|
|
|
|
|
|
|
|
|
|
const fields = req.query.fields as string[]; |
|
|
|
const fields = req.query.fields as string[]; |
|
|
|
|
|
|
|
|
|
|
|
const data = XLSX.utils.json_to_sheet(dbRows, { header: fields }); |
|
|
|
const data = XLSX.utils.json_to_sheet( |
|
|
|
|
|
|
|
dbRows.map((o: Record<string, any>) => |
|
|
|
|
|
|
|
Object.fromEntries(fields.map((f) => [f, o[f]])) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
{ 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' }); |
|
|
|
|
|
|
|
|
|
|
|
res.set({ |
|
|
|
res.set({ |
|
|
|
'Access-Control-Expose-Headers': 'nc-export-offset', |
|
|
|
'Access-Control-Expose-Headers': 'nc-export-offset', |
|
|
|
'nc-export-offset': offset, |
|
|
|
'nc-export-offset': offset, |
|
|
|