xlsx-template
xlsx-template copied to clipboard
Placeholder in table header names may lead to corrupted generated xlsx file
Using an object to substitute placeholders in table header names results in an Excel file that needs to be repaired while the replacement is done. Templates are joint.
This works fine:
// Load an XLSX file into memory
fs.readFile('./template2.xlsx', function (err, data) {
// Create a template
var template = new XlsxTemplate(data);
// Replacements take place on first sheet
var sheetNumber = 1;
// Set up some placeholder values matching the placeholders in the template
var values = {
columnName: 'Will have to be repaired'
};
// Perform substitution
template.substitute(sheetNumber, values);
// Get binary data
var fileData = template.generate();
fs.writeFileSync('./output2.xlsx', fileData, 'binary');
});
This doesn't:
// Load an XLSX file into memory
fs.readFile('./template1.xlsx', function (err, data) {
// Create a template
var template = new XlsxTemplate(data);
// Replacements take place on first sheet
var sheetNumber = 1;
// Set up some placeholder values matching the placeholders in the template
var values = {
column: { name: 'Will have to be repaired'}
};
// Perform substitution
template.substitute(sheetNumber, values);
// Get binary data
var fileData = template.generate();
fs.writeFileSync('./output1.xlsx', fileData, 'binary');
});