Discussion Locked

Perl Program

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How I can open an existing csv file with Excel 2000,add colomns and run a formula on those columns using a perl script.I am trying a test script by which I am able to open an excel file but I am not able to open a csv file.
Below is the script
useWin32::OLE;
use Win32::OLE::Const;
my $wd = Win32::OLE::Const->Load("Microsoft Excel 8.0 Object Library");

# use existing instance if Excel is already running
eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $ex) {
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";
}

$time = localtime;
# open a workbook, activate the first sheet and write header
$book = $ex->Workbooks->Open( 'test.csv' );
$sheet = $book->Worksheets(sheet2);
$sheet->Cells(1,1)->{Value} = "Spool Files Deleted by Date"

If there are any ideas how to convert an execel file run an macro add columns and then save it as csv those are also welcome asthese can be done with a single perl script.
As far as I know perl cannot save into csv format so I am converting the file manually to csv then trying to modify it.

3 replies

by geoffreyc

Excel doesn't operate on CSV, I believe it converts it to Excel style internally. I think you need to use File>>Save As then change the type to CSV to save an excel workbook/sheet as CSV. How this translates into Win32::OLE I don't know.

You could do all the work in Excel then 'Save As' CSV using Excel rather than converting manually.

Also, the modules Spreadsheet::ParseExcel and WriteExcel may help.

This discussion is closed to new replies.