Re: Finnish alphabet and special characters

153 views
Skip to first unread message

jmcnamara

unread,
Dec 7, 2012, 11:23:42 AM12/7/12
to spreadsheet...@googlegroups.com
On Friday, December 7, 2012 2:58:47 PM UTC, MikkoM wrote:
I have a script that retrieves security group memberships from Active Directory. The output is in CSV format (although in-memory during the entire process) which I later transform into an Excel file using Excel::Writer::XLSX. Everything else is Ok, but one really important thing stands in my way; the finnish Alphabet. In the resulting Excel all characters such as Ä and Ö become gibberish. I'm using Net::LDAP within the Perl script to fetch the information from Active Directory, and if I print the CSV data out on console I can see that characters are as they should. But it's the Excel file that doesn't get them right. The problem basically affects employee names, which comes from the LDAP object attribute "displayName". I think this is UTF-8 in Active Directory and that is also how Net::LDAP passes it forward.

I'm running the script on Centos 6.3 and opening the Excel file using Windows 7 and Office 2010. Any ideas what could affect the character encoding?
 
Hi,
 
Excel::Writer::XLSX's handling of UTF-8 is simple. If the string is a UTF-8 string then it gets written as UTF-8. Excel::Writer::XLSX doesn't do any manipulation of the encoding.
 
It works fine in most cases. See for example the unicode example programs starting from here:
 
 
If it fails to work, like in your case, then it is usually due to the string being UTF-8 but not having the utf8 flag set in Perl.
 
You could try resolve this using the Encode module to check if the string is really UTF-8 with Encode::is_utf8() (or more accurately utf8 (sorry this gets confusing)). If it isn't then you could try setting the utf8 flag with Encode::_utf8_on().
 
See the Encode module for more details. http://perldoc.perl.org/Encode.html
 
John.
 
 
 
 
 
 
 
 
 
 
 




  Perl version   : 5.010001
    OS name        : linux
    Module versions: (not all are required)
                     Spreadsheet::WriteExcel    (not installed)
                     Parse::RecDescent          (not installed)
                     File::Temp                 0.22
                     OLE::Storage_Lite          (not installed)
                     IO::Stringy                (not installed)

Reply all
Reply to author
Forward
0 new messages