excel4node
excel4node copied to clipboard
Unable to open files in MS Excel
I have problem,I am unable to open the validated excel in MS excel 10.Got opened in Libre Office. Code: // Create a new instance of a Workbook class const wb = new xl.Workbook();
// Add Worksheets to the workbook
const ws = wb.addWorksheet('Sheet 1');
// Columns to import
const columns = ['Complex', 'Field', 'HasLight', 'League', 'Area', 'Timezone', 'Address1', 'State', 'City', 'Country'];
// Add headers
for (let i = 0; i < columns.length; i++) {
ws.cell(1, i + 1)
.string(columns[i])
}
ws.addDataValidation({
type: 'list',
allowBlank: true,
prompt: 'Choose from dropdown',
error: 'Invalid choice was chosen',
showDropDown: true,
sqref: 'C2:C10',
formulas: ['YES,NO'],
});
ws.addDataValidation({
type: 'list',
allowBlank: true,
prompt: 'Choose from dropdown',
showDropDown: true,
sqref: 'D2:D10',
formulas: ["test,test1"],
});
ws.addDataValidation({
type: 'list',
allowBlank: true,
prompt: 'Choose from dropdown',
error: 'Invalid choice was chosen',
sqref: 'F2:F10',
formulas: ["test,test1"],
});
ws.addDataValidation({
type: 'list',
allowBlank: true,
prompt: 'Choose from dropdown',
error: 'Invalid choice was chosen',
showDropDown: true,
sqref: 'J2:J10',
formulas: ["test,test1"],
});
wb.write('NewExcelFile.xlsx');
@karan-jaryal Thanks for the bug report and the code example! Are you using the latest version of the excel4node library? I am unable to reproduce this issue, but I am testing with Excel 2016 on both Mac and Windows. I don't have access to test with version 10 as Microsoft no longer supports that version
Yes I am using the latest version.I have tested it on excel 2016 its not working there.It ask’s for excel repair
I am too faced same issue with Office 2010. Excel is asking for repair, after repair there is a xml log:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error015800_01.xml</logFileName><summary>Errors detected in file "C:\Users\user\Downloads\ExcelFile
(2).xlsx"</summary><repairedRecords summary="Here is the fixes made:"><repairedRecord>Restored parts: Sheet properties
from /xl/workbook.xml (Book)</repairedRecord></repairedRecords></recoveryLog>
What sheet properties could lead to that errors? I've noticied that it's happens when I clicked several times on download link. 1st time no errors, after all broken. It seems that wb object is not destroyng automatically on sever side. Is there any wb.destroy command?
I think I fixed that by doing something like:
let xl = require('excel4node');
let filename="test.xlsx"
let wb = new xl.Workbook();
let ws=wb.addWorksheet('test');
ws.cell(5, 3).string(mytest);
ws.cell(6, 3).string('Outside of print area, not included in printing');
res
.set('content-disposition', `attachment; filename="${filename}"; filename*=UTF-8''${encodeURI(filename)}`) // filename header
.type('.xlsx') // setting content-type to xlsx. based on file extention
wb.write(filename, res);
wb=null;
ws=null;