Open serfend opened 1 year ago
Transform your date to a JS date, like README file: https://github.com/optilude/xlsx-template?tab=readme-ov-file#generating-reports
It is not working.
It is not working.
Could you create a repository with your example of use? Maybe by visualizing I can help you.
import XlsxTemplate from 'xlsx-template';
import fs from 'fs';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
// Determine the directory name in an ES module
const __dirname = dirname(fileURLToPath(import.meta.url));
// Load an XLSX file into memory
fs.readFile(path.join(__dirname, '/', 'template.xlsx'), function (err, data) {
if (err) {
throw err; // Handle errors here if the file cannot be read
}
// 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 = {
extractDate: new Date('2013-06-01'),
};
// Perform substitution
template.substitute(sheetNumber, values);
// Get binary data
var newData = template.generate({ type: 'nodebuffer' });
// Write the new data to a file
fs.writeFile(
path.join(__dirname, '/', 'output.xlsx'),
newData,
function (err) {
if (err) {
throw err; // Handle the error here
}
console.log('The file has been saved!');
}
);
});
I have formatted the cell for date
But the output excel file does not have formatted date
I need to do double click + Enter on the cell to get expected format as below
same issue as this
It is not working.
ignore my previous comments. It's working when using js Date instead of plain string.
while put value
2023-08-09 14:44:32
into template ${datetime} on which cell formatYY-MM-DD
, you will get2023-08-09 14:44:32
instead of2023-08-09