Spreadsheet::WriteExcel

This is a fabulous implementation of perl:
cpan WriteExcel page

Below is one of Mr. McNamara’s scripts with a few changes, I include is just as an example:

#!/usr/bin/perl -w

##############################################################################
#
# A simple example of converting some Unicode text to an Excel file using
# Spreadsheet::WriteExcel and perl 5.8.
#
# This example generates some Thai from a file with ISO-8859-11 encoded text.
#
#
# reverse('©'), September 2004, John McNamara, jmcnamara@cpan.org
#



# Perl 5.8 or later is required for proper utf8 handling. For older perl
# versions you should use UTF16 and the write_unicode() method.
# See the write_unicode section of the Spreadsheet::WriteExcel docs.
#
require 5.008;

use strict;
use Spreadsheet::WriteExcel;


my $workbook  = Spreadsheet::WriteExcel->new("/buxs/htdocs/sample.xls");
my $worksheet = $workbook->add_worksheet('info');
#   $worksheet->set_column('A:A', 20);


my $file = 'excel_test.txt';

open FH, '<:encoding(iso-8859-11)', $file  or die "Couldn't open $file: $!\n";

my $row = 0;

while () {
    next if /^#/; # Ignore the comments in the sample file.
    chomp;
    my $line = $_;
    my @fields = split /\t/, $line;
    my $col = 0;
      foreach(@fields)
        {
        $worksheet->write($row, $col++, $_);
        }
   $row++;
}

close FH;

open FHT, '<:encoding(iso-8859-11)', 'excel_test2.txt'  or die "Couldn't open $file: $!\n";

$worksheet = $workbook->add_worksheet('info2');

$row = 0;

while () {
    next if /^#/; # Ignore the comments in the sample file.
    chomp;
    my $line = $_;
    my @fields = split /\t/, $line;
    my $col = 0;
      foreach(@fields)
        {
        $worksheet->write($row, $col++, $_);
        }
   $row++;
}

close FHT;

Leave a Reply

Your email address will not be published. Required fields are marked *