in reply to Spreadsheet::WriteExcel with UTF-8 text


With the latest versions of Spreadsheet::WriteExcel and Perl 5.8 you can use the UTF-8 text directly. See this Japanese example in the distro and the text file that it reads.

With older versions of Perl you will have to use a module to convert the UTF-8 to UTF-16BE. See also this example. Note you may also have to specify a Unicode font (although this is generally the default with newer versions of Excel).

If you dealing with UTF-8 data I would strongly recommend using Perl 5.8 if you aren't already.

--
John.

  • Comment on Re: Spreadsheet::WriteExcel with UTF-8 text

Replies are listed 'Best First'.
Re^2: Spreadsheet::WriteExcel with UTF-8 text
by Anonymous Monk on Mar 03, 2005 at 10:56 UTC
    Thank you very much for your help. I believe I have identified the problem...not having much experience with Windows, I didn't consider the question of whether the Excel version would be able to display Japanese characters. As your example spreadsheet gives the same type of results as my spreadsheet, I think the problem lies with interpretation, not writing.

    Once again, thank you.


      Some versions of Excel aren't installed with Unicode fonts by default. If you have one installed but Excel isn't associating it with your strings you tell it to by adding something like this to your program:
      ... # Set a Unicode font. my $uni_font = $workbook->add_format(font => 'Arial Unicode MS'); $worksheet->write('A1', $utf8_str, $uni_font); ...

      --
      John.

        This is several years old--Excel 2000 9.0.2720. I'd have to look it up specifically to see if it has support, but given the age, if I had to guess, I'd guess not. Thanks for the tip; I will try it if someone with a newer version of Excel reports the same problem.
Re^2: Spreadsheet::WriteExcel with UTF-8 text
by Anonymous Monk on Mar 03, 2005 at 10:46 UTC
    I should have specified: I am using Spreadsheet::WriteExcel version 2.11 and Perl version 5.8.5. As this appears to be the most recent WriteExcel version, I intend to test your example to see if the fault might lie elsewhere.

    Thank you for your suggestions.