1#!/usr/local/bin/perl -w
2
3##############################################################################
4#
5# A simple example of converting some Unicode text to an Excel file using
6# Spreadsheet::WriteExcel and perl 5.8.
7#
8# This example generates some Russian from a file with CP1251 encoded text.
9#
10#
11# reverse('�'), September 2004, John McNamara, jmcnamara@cpan.org
12#
13
14
15
16# Perl 5.8 or later is required for proper utf8 handling. For older perl
17# versions you should use UTF16 and the write_utf16be_string() method.
18# See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
19#
20require 5.008;
21
22use strict;
23use Spreadsheet::WriteExcel;
24
25
26my $workbook  = Spreadsheet::WriteExcel->new("unicode_cp1251.xls");
27my $worksheet = $workbook->add_worksheet();
28   $worksheet->set_column('A:A', 50);
29
30
31my $file = 'unicode_cp1251.txt';
32
33open FH, '<:encoding(cp1251)', $file  or die "Couldn't open $file: $!\n";
34
35my $row = 0;
36
37while (<FH>) {
38    next if /^#/; # Ignore the comments in the sample file.
39    chomp;
40    $worksheet->write($row++, 0,  $_);
41}
42
43
44__END__
45
46