xlsx-populate
xlsx-populate copied to clipboard
Workaround: page setup, fit to page, page breaks
We found the following workaround regarding a fit to page configuration based on a blank workbook:
import Excel from 'xlsx-populate/browser/xlsx-populate.js';
import downloadjs from 'downloadjs';
// ...
// create workbook
const wb = await Excel.fromBlankAsync();
const ws = wb.sheet(0);
// add some content
// ...
// page and print configuration
ws._sheetPrNode.children.push({
name: "pageSetUpPr",
children: [ ],
attributes: {
fitToPage: '1',
}
});
ws._node.children.push({
name: "pageSetup",
children: [ ],
attributes: {
paperSize: '9',
orientation: 'landscape',
fitToWidth: '1',
fitToHeight: '0',
}
});
// download as file
downloadjs(
await wb.outputAsync(),
fileName + '.xlsx',
Excel.MIME_TYPE
);
// ...
In case you want to set manual pake breaks, the following snippet might help:
ws._node.children.push({
name: "colBreaks",
children: [{
name: "brk",
children: [ ],
attributes: {
id: '17', // column number
max: '1048575',
man: '1',
}
}],
attributes: {
count: '1',
manualBreakCount: '1',
}
});
Feel free to submit a PR with proper methods for this. :)
Can you please help me add a header and footer to all pages while printing?
sheet.printOptions().orientation("landscape"); 🥲
Sheet.printOptions: Invalid arguments.