-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Hi, this package is wonderful!
And I have only one issue, when I generate my worksheets from the below code, and then try to open with Excel it thinks the file is corrupted or something and proposes the open to Open and repair, which after doing I get the log in the bottom (which doesn't say much :/). Any ideas on what could be causing this?
Otherwise, the file looks good when repaired.
import flatten from 'flat';
import xlsx from 'xlsx-stream';
import _ from 'lodash';
app.listen('/export', (req, res) => {
const filename = 'FILE.xlsx';
const data = { data: [{a: 1, b: 2, c: 3}] };
const worksheets = xlsx();
res.set({
'Content-type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8',
'Content-Disposition': `attachment; filename=${encodeURI(filename)}`,
});
res.status(200);
worksheets.pipe(res);
// Build worksheets.
_.each(data, (items, name) => {
let headers = false;
// const sheet = worksheets.sheet(name);
if (items instanceof Array) {
_.each(items, (item) => {
const row = flatten(item);
if (!headers) {
// sheet.write(Object.keys(row));
worksheets.write(Object.keys(row));
headers = true;
}
// sheet.write(Object.values(row));
worksheets.write(Object.values(row));
});
} else {
const row = flatten(items);
if (!headers) {
// sheet.write(Object.keys(row));
worksheets.write(Object.keys(row));
headers = true;
}
// sheet.write(Object.values(row));
worksheets.write(Object.values(row));
}
// sheet.end();
worksheets.end();
});
worksheets.finalize();
});<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>Repair Result to FILE.xml</logFileName>
<summary>Errors were detected in file '/Users/tim.brandin/Downloads/FILE.xlsx'</summary>
<additionalInfo>
<info>Excel completed file level validation and repair. Some parts of this workbook may have
been repaired or discarded.</info>
</additionalInfo>
</recoveryLog>
And that was all she wrote, I wish I had more to go on, but all generated files become this way.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels