raja567 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to print the text "ID Serviço Vantive" in excel sheet using the following code, but in Excel it is getting displayed as "ID Sevio Vantive". The character 'ç' is getting missed, I know it is because of encoding,decoding of characters but tried few ways to fix it and none of them worked. Can anyone help me how to get rid of this problem?

use Locale::Msgcat; use Number::Localization; use Presentation; use utf8; use Encode ; my $rowCount = 0; my $colCount = 0; my $Field = ""; my $workbook = Excel::Writer::XLSX->new('test.xlsx'); $worksheet = $workbook->add_worksheet(); $worksheet->set_column( 0, 10, 40 ); my $gFmtBold = $workbook->add_format(); $gFmtBold->set_bold(); $gFmtBold->set_size(15); $gFmtBold->set_color('black'); $gFmtBold->set_align('center'); my $normalFmt = $workbook->add_format(); $normalFmt->set_align('center'); my (@outRecord); @outRecord = ("Nome do Produto","ID Serviço Vantive","Motivo","Quantid +ade"); foreach $Field (@outRecord) { $worksheet->set_column($rowCount,$colCount,40); $worksheet->write($rowCount,$colCount,decode('utf8',$Field),$gFm +tBold); $colCount++; }

Replies are listed 'Best First'.
Re: Printing portugese text in Excel
by choroba (Cardinal) on Apr 20, 2015 at 10:00 UTC
    Just remove the call to decode:
    $worksheet->write($rowCount, $colCount, $Field, $gFmtBold);

    I also had to remove the following lines from the script to test it (they're irrelevant to the question, anyway):

    use Locale::Msgcat; use Number::Localization; use Presentation;

    And I had to prepend

    use Excel::Writer::XLSX;

    See Short, Self Contained, Correct Example on how to help us to help you.

    See the module's documentation on the details:

    If the data is in UTF-8 format then Excel::Writer::XLSX will handle it automatically.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Hi, I tried that and it is still showing "ID Servio Vantive" in excel sheet.

        Are you sure your program is saved as UTF-8? It works for me.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Printing portugese text in Excel
by pme (Monsignor) on Apr 20, 2015 at 10:47 UTC
    Hi raja567,

    This works for me (perl 5.18.2).

    use strict; use Excel::Writer::XLSX; use utf8; my $rowCount = 0; my $colCount = 0; my $Field = ""; my $workbook = Excel::Writer::XLSX->new('test.xlsx'); my $worksheet = $workbook->add_worksheet(); $worksheet->set_column( 0, 10, 40 ); my $gFmtBold = $workbook->add_format(); $gFmtBold->set_bold(); $gFmtBold->set_size(15); $gFmtBold->set_color('black'); $gFmtBold->set_align('center'); my $normalFmt = $workbook->add_format(); $normalFmt->set_align('center'); my (@outRecord); @outRecord = ("Nome do Produto","ID Serviço Vantive","Motivo","Quantid +ade"); foreach $Field (@outRecord) { $worksheet->set_column($rowCount,$colCount,40); $worksheet->write($rowCount,$colCount,$Field,$gFmtBold); $colCount++; }