xlsx-template
xlsx-template copied to clipboard
Uncaught TypeError: this._factory is not a function
test('xls report file should be created again', async () => {
let values = {
lastName: 'Тестов',
firstName: 'Тест',
middleName: 'Тестович',
};
const XlsxTemplate = require('xlsx-template');
// Load an XLSX file into memory
fs.readFile(path.join(__dirname, 'Book1.xlsx'), function(err, data) {
// Create a template
const template = new XlsxTemplate(data);
// Replacements take place on first sheet
const sheetNumber = 1;
// Set up some placeholder values matching the placeholders in the template
// Perform substitution
template.substitute(sheetNumber, values);
// Get binary data
const generated = template.generate();
fs.writeFileSync('B1.xlsx', generated, 'binary')
});
});
in Book1.xlsx - one simple string ${lastName} nothing more then run this test you get: Uncaught TypeError: this._factory is not a function
Couple questions:
- What's NodeJS version?
- Are this is new test or existing one?
In the offline chat we discover that changing fs.readFile to fs.readFileSync at least unblock the issue. so far there no conclusive reason why issue happens.
I would speculate that when called inside async context this line produce some issues https://github.com/racker/node-elementtree/blob/master/lib/treebuilder.js#L8
I waiting for smallest @ronxbysu case and will start troubleshooting from this point