use strict;
use warnings;
use Win32::OLE::Const;
use Win32::OLE::Const 'Microsoft Excel';
my $path = 'C:\Delme~~';
my $Excel = Win32::OLE->new ("Excel.Application", sub { $_[0]->Quit })
or die Win32::OLE::LastError;
$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Add ();
my $Sheet = $Book->Worksheets ('Sheet1');
$Sheet->Range ('A1')->{Value} = "Hello World";
$Sheet->Range ('A2')->{Value} = "Hi World";
$Excel->{DisplayAlerts} = 0; # avoid being prompted
$Sheet->SaveAs ({FileName => "$path\\test.txt", FileFormat => xlText
+})
or die Win32::OLE::LastError;
$Book->Close ();
$Excel->Quit;
open IN, '<', "test.txt";
print <IN>;
close IN;
Prints:
Hello World
Hi World
Perl is environmentally friendly - it saves trees
|