function table_to_book returns a date if td element contains text "marks" followed by a number
my data has text like "Tally marks - up to 10" and "Tally marks - up to 20" in td element of my html. When I convert this data to xlsx it returns a date object like this
A4:{t: "n", v: 36586, z:"m/d/yy"}
instead of same text value. I have then tried to figure it out what is causing it. So I concluded that if there is a word "marks" followed by a number then it shows this kind of behavior.
Why is it showing this behavior.
The error comes from the Chrome date logic:
new Date("Tally marks - up to 10") // Sat Mar 10 2001 00:00:00 GMT-0500 (EST)
To avoid matching those, the reader checks for a short month name, and of course "Marks" happens to contain "Mar".
Until it is resolved, passing raw:true bypasses the value guessing logic.
@reviewher should I pass raw:true like this
var worksheet = XLSX.utils.table_to_book(document.getElementById(tableId), {raw : true});
I have tried this but this is not working. let me know if I am doing something wrong.
Also I am writing the file like this
var wopts = { bookType:'xlsx', bookSST:false, type:'binary', raw: true};
var wbout = XLSX.write(worksheet, wopts);
Your first line is correct. Are you using the latest version? console.log(XLSX.version) will tell you, and the current release is 0.11.2
Just as a sanity check, try going to http://sheetjs.com/demos/table and editing the number 4 to Marks 4, then open the console and run:
XLSX.utils.table_to_book(document.getElementById('table')).Sheets.Sheet1.D3
// {t: "n", v: 36954.041666666664, z: "m/d/yy"}
XLSX.utils.table_to_book(document.getElementById('table'), {raw:true}).Sheets.Sheet1.D3
// {t: "s", v: "Marks 4"}
@reviewher Thank you so much for helping me out here. putting raw: true and updating library to latest version fixed it for me.
God Bless You
Glad that worked :)
I would like to know how to use the raw parameter but at the same time, format the numeric columns in a way that im still allowed to add the values in excel.
Currently that's not possible.
For a customer of our Pro offering, we added a backdoor rawDates option that skips the entire date parsing logic. We can do something similar here too.
@reviewher Thank you so much for helping me out here. putting raw: true and updating library to latest version fixed it for me.
Best Regards