-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When converting json to text it is converting characters weirdly #2624
Comments
XLSX.write(workBook, {bookType: "csv", type: "string"}); // CSV as a JS string
XLSX.utils.sheet_to_csv(workSheet); // CSV from a worksheet (JS string)
When using |
Ok, so I've tried sheet_to_txt and write{bookType:'txt'}) and both are rendering the same way. Now I will say, that when I filter and convert one line, it is rendering the ’ character correctly. HOWEVER, when I return all 10,000 lines of data, it is then returning ’. Is there a reason why a small subset of data renders correctly, but the full set of data replaces certain characters? |
Does the same thing happen with CSV (using In either case, can you share a sample? |
Here is the file. So weirdly I have an array of 10,000 lines. In trying to help get a smaller set of data I found that if I include 978-1232 it didn't work. If I took 979-5000 it worked. So this file contains lines 978-1232. So in translation, the file on here is 1-255. So if I include line 1 in the sheet_to_txt it messes up the values. If I remove the first line, it works correctly. Code:
|
Please test the following: results = XLSX.utils.sheet_to_txt(workSheet, {type: "string"}); If this works, the issue can be resolved with a small patch to https://github.com/SheetJS/sheetjs/blob/master/bits/90_utils.js#L153 (feel free to submit a PR): if(typeof $cptable == 'undefined' || opts.type == 'string' || !opts.type) return s; |
Sadly it did not work and returned the same results :. Now I have pulled out the file since I'm working in a cloud system called Netsuite, so all I'm importing a file from either node_modules/xlsx/xlsx.js or node_modules/xlsx/dist/xlsx.extendedscript.js. |
Is there a way to read the content of json_to_sheet? That way I could determine if the file is being incorrectly manipulated there? |
The result is a plain JS object, you can directly inspect it. To get a specific cell, you can index with an Excel address: var A1 = workSheet["A1"]; Please try using node_modules/xlsx/dist/xlsx.full.min.js or node_modules/xlsx/dist/xlsx.core.min.js (and be sure to pull the latest version from npm!). node_modules/xlsx/xlsx.js is designed for use in NodeJS. Some small test https://jsfiddle.net/sheetjs/vmez8u1g/ shows the effect of the parameters. |
Continuing with the weird, in sheet_to_csv I added this Ok, I'll try that and see. When I tried importing it in requirejs it was causing some issues and I couldn't run it. |
For whatever reason I cannot get it to load the xlsx.min.js nor xlsx.core.min.js to load using requirejs inside of Netsuite. |
NetSuite support was verified working in 0.16.1 and there was no change to the RequireJS logic since then. Is there some reported error? |
Ok, I have the xlsx.full.min.js working and I'm still getting the same issue. So I'm not sure if the code is converting it to a different character or if it is the javascript version causing the issue. since the issue seems to be when converting out to a string. |
When converting json data to a text or csv it is converting characters like ’ to ’
I see that changing it to use UTF will supposedly fix it according to other documents, but I only see the use case when reading the file and not writing/creating the document.
In your documentation it says that 'txt' is UTF-16, but "string" is UTF8. How would I go about changing that, or can I?
The text was updated successfully, but these errors were encountered: