Reading xls file is returning html tags using library xlsx
I am using xlsx library of nodejs for reading xls file. According to the document the library supports xls file format. On reading I am getting html tags along with it. I can remove the html tags using regex or replace function but does the library give support to do that as I couldn't find it in the documentation?
Excel File format: Microsoft Excel 97-2003 Worksheet (.xls)
The demo link provided in their documentation https://oss.sheetjs.com/sheetjs/ works but when I try to do the same with my code it doesn't give the desired result.
let xlsx = require('xlsx');
let fs = require('fs');
let workBookData = xlsx.readFile('data.xls'); // parses a file
console.log(workBookData);
Here is an image of the result I am getting.
Can you share the file?
Attached please find.
From: reviewher @.> Sent: Saturday, December 4, 2021 1:49 AM To: SheetJS/sheetjs @.> Cc: Abdullah Hassan @.>; Author @.> Subject: Re: [SheetJS/sheetjs] Reading xls file is returning html tags using library xlsx (Issue #2469)
Can you share the file?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SheetJS/sheetjs/issues/2469#issuecomment-985818331, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AR7OMVYSNBT5MGYVRKQF4TTUPEUNBANCNFSM5JKEBXEQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Cannot reproduce with the latest version of the library and NodeJS LTS:
$ md5sum Report_Billings.xls
5103c7ab4790083ce102ae86634a19a5 Report_Billings.xls
$ node --version
v16.13.1
$ node -pe 'require("xlsx").version'
0.17.4
$ node -pe 'require("xlsx").readFile("Report_Billings.xls").Sheets.Sheet1.A1'
{ v: 'Statement No.', t: 's', w: 'Statement No.' }
Are you absolutely sure you attached the same file? If you can't share it publicly, feel free to email it directly to [email protected] and we can look at it further
Cannot reproduce with the latest version of the library and NodeJS LTS:
$ md5sum Report_Billings.xls 5103c7ab4790083ce102ae86634a19a5 Report_Billings.xls $ node --version v16.13.1 $ node -pe 'require("xlsx").version' 0.17.4 $ node -pe 'require("xlsx").readFile("Report_Billings.xls").Sheets.Sheet1.A1' { v: 'Statement No.', t: 's', w: 'Statement No.' }Are you absolutely sure you attached the same file? If you can't share it publicly, feel free to email it directly to [email protected] and we can look at it further
Forwarded, please have a look, and suggest.
Thanks for sharing! The actual file was an HTML file renamed to XLS
The opening tag had inline styles with a semicolon:
<table cellspacing="0" rules="all" border="1" style="border-collapse:collapse;">
This tripped up the check in https://github.com/SheetJS/sheetjs/blob/master/bits/75_xlml.js#L185
We'd accept a PR that ignores characters within double quotes:
--- a/bits/75_xlml.js
+++ b/bits/75_xlml.js
@@ -183,6 +183,7 @@ function parse_xlml_xml(d, _opts)/*:Workbook*/ {
else str = utf8read(str);
}
var opening = str.slice(0, 1024).toLowerCase(), ishtml = false;
+ opening = opening.replace(/".*?"/g, "");
if((opening.indexOf(">") & 1023) > Math.min((opening.indexOf(",") & 1023), (opening.indexOf(";")&1023))) { var _o = dup(opts); _o.type = "string"; return PRN.to_workbook(str, _o); }
if(opening.indexOf("<?xml") == -1) ["html", "table", "head", "meta", "script", "style", "div"].forEach(function(tag) { if(opening.indexOf("<" + tag) >= 0) ishtml = true; });
if(ishtml) return HTML_.to_workbook(str, opts);
@SheetJSDev Hi, Was facing the same issue, have made a PR following your suggestions, I am curios to know when npm package will be updated accordingly.
30c03a2e5341ec808c299c72dbd9da4fb414b874
@SheetJSDev When we will expect npm package to be updated for this change.