infor-design / enterprise

Enterprise-grade component library for the Infor Design System
https://design.infor.com
Apache License 2.0
134 stars 81 forks source link

Datagrid: Export to CSV with special characters (é, à, ü, ...) #4347

Closed afarn closed 4 years ago

afarn commented 4 years ago

Export to CSV with special characters (é, à, ü, û, ...) does not generate them correctly.

datagrid

Excel_file

EdwardCoyle commented 4 years ago

Reported on MS Teams

sanx72 commented 4 years ago

FYI - also had this issue reported from one of our French customers. We found that the Unicode BOM was missing from the CSV file. If we edited the CSV file in Notepad, then saved as Unicode (not UTF-8) then opened the file again in Excel, characters were displayed OK.

tmcconechy commented 4 years ago

I do have a question if this is actually partly fixed since the example page at https://master-enterprise.demo.design.infor.com/components/datagrid/example-export-from-button.html shows some of these characters in the test. And i see that the excel export button works but the CSV file doesnt.

sanx72 commented 4 years ago

@tmcconechy yes it is the CSV one that doesn't work, which I believe is the default Export option on the data grid (in this example they are manually added export button options). The exportToExcel API method appears to work, but puts the XML wrapper around the data that then throws warnings in Excel when opened so, for our application, this is not acceptable.

tmcconechy commented 4 years ago

Yeah cant seem to get around the warning unless we include a complete excel parser. Will look at the CSV issue soon. The warning is https://github.com/infor-design/enterprise/issues/2995 - we "want" to fix it but looking for time

sanx72 commented 4 years ago

@tmcconechy Just looked at the solution for this, and the code appears to be setting a Unicode BOM but then encoding the save file as charset=UTF-8. You might want to review this again as in our own CSV save, we had to convert the CSV data (which will be in a UTF-16 string) to a byte array with a BOM (FF FE) and then put that into the Blob to save as charset=UTF-16. This was the only way we could get Excel to recognise non-ANSI characters.

tmcconechy commented 4 years ago

@sanx72 how does that translate to a change in the code? Do you have a recommendation? cc @deep7102

deep7102 commented 4 years ago

@sanx72 I tested with excel on mac and windows using different browsers and looks fine those all the chars on test-page below, do you having some other set of chars you see issue. Please tell info browser, operating system or excel version etc https://master-enterprise.demo.design.infor.com/components/datagrid/example-export-from-button.html

sanx72 commented 4 years ago

Have you tried this export with sep=; (i.e. for French or other countries where comma is used in numerics for decimal). That was where I hit a problem anyway, with anything other than sep=, Excel import failed with UTF-8 BOM, but OK with UTF-16 BOM.

sep=; "Product Id";"Product Name";"Quantity";"Price";"Status";"Extra";"Filtered" "2142201";"Compressor";"1";"500,00";"OK";"ç ñ ÄËÏÖÜ äëïöü";"true" "2241202";"Different Compressor";"2";"210,99";"";"àèìòù";"true" "2342203";"Compressor";"1";"120,99";"";"áéíóú";"" "2445204";"Another Compressor";"3";"2.345,00";"OK";"ية (مصر";"true" "2542205";"I Love Compressors";"4";"210,99";"OK";"'=HYPERLINK(""http://www.google.com"";""Please Click For More Info"")'";"" "2642205";"Air Compressors";"41";"120,99";"OK";"";"" "2642206";"Some Compressor";"41";"123,99";"OK";"";"true"

image

afarn commented 4 years ago

I tried with the sep=";" but it doesn't work.

afarn commented 4 years ago

For the separator ";" it works with this condition in excel.js (line 368) : if (separator.firstLine && separator.char ! == ',' && separator.char ! == ';') { csv.unshift ([sep = $ {separator.char}]); }

proposition : For Angular, I propose to change the declaration of the exportToCsv function (but it is not mandatory) as follows: exportToCsv(fileName: string, customDs: Object[], separator: string | {})

and for example we can call this function like: exportToCsv(‘toto’, undefined, { firstLine: false, char: ' ;' }) ;

janahintal commented 3 years ago

This issue is now resolved. Thank you. :) image