I'm using node-xlsx to try and write a simple data structure to a new Excel file. When it gets written, I see no quotation marks around the cell data yet when I upload the file into a browser using automation, it gets rejected because quote marks have been added to all the string values. I'm not clear why this is happening
The code:
export async function createExcelFile(testInfo, fileType,
adaptationId) {
const [tomorrow, nextMonth] = await getDatesForFiles();
const data = [
{
'storeNumber': 33228,
'adaptationId': parseInt(adaptationId),
'effectiveFrom': tomorrow.replaceAll('"', ''),
'effectiveTo': nextMonth.replaceAll('"', '')
}
];
// @ts-ignore
const buffer = xlsx.build([{name: "Sheet One", data: data}], {
cellDates: false });
//write the buffer to a file in a temp folder
const tempFileName = uuid.v4() + '.xlsx';
const tempFilePath = path.join(process.cwd(), 'src' ,'test-data',
'temp-files', tempFileName);
fs.writeFileSync(tempFilePath, buffer);
return [tempFileName, buffer];
}
All values except for the number 33228
are affected so looks like this is a lead - how can I prevent this behaviour? Using replace()
with a regex seems to have no effect.
I am using Playwright's fileChooser function to do the upload and I wonder if the error lies here?
await fileChooser.setFiles({
name:fileName,
mimeType:'application/vnd.ms-excel',
buffer: Buffer.from(buffer)
});
Have you tried using
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
- which is the .xlsx one.application/vnd.ms-excel
is .xls, source