LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Excel Module - perl scripting - specifying encoding format (https://www.linuxquestions.org/questions/programming-9/excel-module-perl-scripting-specifying-encoding-format-596968/)

kshkid 11-03-2007 09:51 PM

Excel Module - perl scripting - specifying encoding format
 
Hi All,

Am writing a small tool to populate delimited records into an excel sheet
using the module Spreadsheet::WriteExcel.

I want to specify the encoding format of the input file, I don't see a way to do that currently.

Something like,

open an excel sheet
open a CSV file
while importing specify the encoding format ( utf-8 or other formats )

Is there a way to do that ?
Am trying to automate a couple of conversion work.


Your help is much appreciated.

Guttorm 11-05-2007 08:39 AM

Hi

If you install libspreadsheet-writeexcel-perl on a Debian/Ubuntu system, you get a lot of examples in /usr/share/doc/libspreadsheet-writeexcel-perl/examples/

One of those is called unicode.pl

Code:

#!/usr/bin/perl -w

##############################################################################
#
# A simple example of writing some Unicode text with Spreadsheet::WriteExcel.
#
# This example shows UTF16 encoding. With perl 5.8 it is also possible to use
# utf8 without modification.
#
# reverse('©'), May 2004, John McNamara, jmcnamara@cpan.org
#


use strict;
use Spreadsheet::WriteExcel;


my $workbook  = Spreadsheet::WriteExcel->new('unicode.xls');
my $worksheet = $workbook->add_worksheet();


# Write the Unicode smiley face (with increased font for legibility)
my $smiley    = pack "n", 0x263a;
my $big_font  = $workbook->add_format(size => 40);

$worksheet->write_unicode('A3', $smiley, $big_font);


# Write a phrase in Cyrillic
my $uni_str = pack "H*", "042d0442043e002004440440043004370430002004".
                        "3d043000200440044304410441043a043e043c0021";

$worksheet->write_unicode('A5', $uni_str);


$worksheet->write_unicode('A7', pack "H*", "0074006500730074");


kshkid 11-06-2007 10:52 PM

many thanks for the reply :)

I will try it out and update how it goes !

Thanks once again :)


All times are GMT -5. The time now is 06:55 AM.