2
votes

I am writing Excel file through perl code. When I insert data in XML file and view in any browser, I see correct data with special characters, but when I write the same data in Excel file, it is showing garbage characters. For eg.: (word from XML file on browser) Gràcia - (word from Excel file) Grà cia

I am using 'Spreadsheet::XLSX' for reading excel and 'Excel::Writer::XLSX' for writing excel.

Also need help in finding the encoding format of excel fields.

Do you have any idea? Thanks in advance.

1

1 Answers

4
votes

This seems very much like UTF-8 to iso-8859-1 conversion going wrong - seems like a string that contains UTF-8, but is not marked as being UTF-8, is being passed to $worksheet->write(). Since http://metacpan.org/pod/Excel::Writer::XLSX#UNICODE-IN-EXCEL claims to handle unicode correctly, it seems to be a problem with your input string, not the write method itself.

As you don't post any code, and don't tell us where your strings come from, i can't tell why the strings aren't marked correctly.

You can probably get away with

Encode::_utf8_on($str)

before passing your strings to $worksheet->write(), but this might just as well break other things, if not all of your strings are really utf-8. Basically the answer is "get the utf-8 flag on your strings right when you read them".