1#!/usr/bin/perl -w 2 3############################################################################## 4# 5# A simple example of converting some Unicode text to an Excel file using 6# Spreadsheet::WriteExcelXML and perl 5.8. 7# 8# This example generates some Arabic text from a CP-1256 encoded file. 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_unicode() method. 18# See the write_unicode section of the Spreadsheet::WriteExcelXML docs. 19# 20require 5.008; 21 22use strict; 23use Spreadsheet::WriteExcelXML; 24 25 26my $workbook = Spreadsheet::WriteExcelXML->new("unicode_cp1256.xls"); 27my $worksheet = $workbook->add_worksheet(); 28 $worksheet->set_column('A:A', 50); 29 30 31my $file = 'unicode_cp1256.txt'; 32 33open FH, '<:encoding(cp1256)', $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