Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Finnish alphabet and Excel::Writer::XLSX

by mellin (Scribe)
on Dec 07, 2012 at 16:44 UTC ( #1007790=perlquestion: print w/replies, xml ) Need Help??
mellin has asked for the wisdom of the Perl Monks concerning the following question:


I have a problem with the Perl module Excel::Writer::XLSX and certain characters such as Ä and Ö in the finnish Alphabet. They seem to become gibberish in the resulting file. I'm running the Perl script in Centos 6.3 and I've viewed the Excel file both in Windows 7 with Office 2010 and in Centos using LibreOffice Calc. Same problem in both. Any ideas what I might be doing wrong?

I have included a short code example below which produces the same issue in my system.

#!/usr/bin/perl -w use strict; use Excel::Writer::XLSX; my $path = '/tmp'; my $time = time(); my $stamp = $time . '-' . $$; my $filename = "$path/$stamp.xlsx"; # Create a new Excel workbook my $workbook = Excel::Writer::XLSX->new($filename); # Add a worksheet my $worksheet = $workbook->add_worksheet(); # set header format my $format = $workbook->add_format( bold => 1, color => 'black'); $worksheet->write(0, 0, 'Name', $format); $worksheet->write(1, 0, 'Mister Mister'); $worksheet->write(2, 0, 'Mäster Mäster'); $worksheet->autofilter(0, 0, 2, 0); $worksheet->freeze_panes(1, 0);

Replies are listed 'Best First'.
Re: Finnish alphabet and Excel::Writer::XLSX
by Anonymous Monk on Dec 07, 2012 at 18:07 UTC

    I'm not familiar with the module in question, but currently Perl will interpret your strings as latin-1. If your source file is saved as UTF-8, Perl will see "Mäster Mäster"

    If you say use utf8;, your strings will contain the correct character sequence (...assuming you saved the source file in UTF-8. Most *nix editors do that by default today.)

    Furthermore, the Excel::Writer::XLSX perldoc contains a "UNICODE IN EXCEL" section which has a few examples on getting your strings to Perl's internal encoding correctly.

Re: Finnish alphabet and Excel::Writer::XLSX
by rpnoble419 (Pilgrim) on Dec 08, 2012 at 00:02 UTC
    I was bitten by Unicode. Remember if you are getting your data from a database and that data contains Unicode you must create the correct DBI connection to the data. I forgot this with MySQL and could not get the data into the correct format for Excel...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007790]
Approved by 2teez
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2018-05-20 14:12 GMT
Find Nodes?
    Voting Booth?