1#!/usr/local/bin/perl -w 2 3############################################################################### 4# 5# This is a simple example of how to create an Excel file using the 6# Win32::OLE module for the sake of comparison. 7# 8# reverse('�'), March 2001, John McNamara, jmcnamara@cpan.org 9# 10 11use strict; 12use Cwd; 13use Win32::OLE; 14use Win32::OLE::Const 'Microsoft Excel'; 15 16 17my $application = Win32::OLE->new("Excel.Application"); 18my $workbook = $application->Workbooks->Add; 19my $worksheet = $workbook->Worksheets(1); 20 21$worksheet->Cells(1,1)->{Value} = "Hello World"; 22$worksheet->Cells(2,1)->{Value} = "One"; 23$worksheet->Cells(3,1)->{Value} = "Two"; 24$worksheet->Cells(4,1)->{Value} = 3; 25$worksheet->Cells(5,1)->{Value} = 4.0000001; 26 27# Add some formatting 28$worksheet->Cells(1,1)->Font->{Bold} = "True"; 29$worksheet->Cells(1,1)->Font->{Size} = 16; 30$worksheet->Cells(1,1)->Font->{ColorIndex} = 3; 31$worksheet->Columns("A:A")->{ColumnWidth} = 25; 32 33# Write a hyperlink 34my $range = $worksheet->Range("A7:A7"); 35$worksheet->Hyperlinks->Add({ Anchor => $range, Address => "http://www.perl.com/"}); 36 37# Get current directory using Cwd.pm 38my $dir = cwd(); 39 40$workbook->SaveAs({ 41 FileName => $dir . '/win32ole.xls', 42 FileFormat => xlNormal, 43 }); 44$workbook->Close; 45