简体   繁体   中英

How can I convert .xls to .xlsx using a nodejs library?

I'm having trouble reading a.xls file using the ExcelJS library. No problems reading.xlsx files. I used to use only the xlsx js library and did not have any issues reading.xls files.

I was under the impression ExcelJS included xlsx library so my assumption was that reading.xls would work as expected.

So my question is...can I convert.xls to.xlsx using exceljs (I cannot require a user to convert the file themselves in excel) or can I somehow implement the unzip from xlsx js library and incorporate it in the exceljs source code to make it possible?

I switched to exceljs because it seemed more straightforward when it comes to creating excel files.

Thanks All

I found a workaround, you can try converting the xls file to CSV with xlsx library and read CSV with ExcelJS.

It doesn't seem to supports converting from xls to xlsx, but if you don't mind forcing users to upload xls file, save the xlsx file and upload it again then here is my codepen for that

        document.getElementById('my_upload').addEventListener('change', function(e) {
            var file = e.target.files[0];
            var reader = new FileReader();
            reader.onload = function(e) {
                var data = e.target.result;
                var workbook = XLSX.read(data, {
                    type: 'binary'
                });
                XLSX.writeFile(workbook, 'test.xlsx');
            };
            reader.readAsBinaryString(file);
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM