#!/usr/bin/perl use strict; use warnings; # # test the magic strings # my $col = 'p'; my $limit = 120; for (-5..$limit) { $col++; print "$col,"; } #### #!/usr/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); # # Based on `Using Win32::OLE and Excel - Tips and Tricks' # by cacharbe - Mar 22, 2002 - node_id=153486.. with thanks 8-) # $Win32::OLE::Warn = 3; my ($ex, # this will be the ref to the Excel application $book, # ref to the entire workbook $sheet, # a particular worksheet $sheetcount) # count of all sheets in workbook = undef; # Check that Excel is running - if not, start it eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $ex) { # if $ex is undef here, need to start Excel $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; } my $excelfile = "D:/murray/cut_test.xls"; # open existing workbook $book = $ex->Workbooks->Open($excelfile); $sheetcount = $book->Worksheets->Count(); # open an output file to take csv formatted results open CURR, ">", "cut_extract.csv" or die "Can't open Extract for writing $!"; # get the "one-off" key information from the top of the Total Summary sheet $sheet = $book->Worksheets("Total Summary"); my $key_values = $sheet->Range("M1:M8")->{Value}; my ($project, $term, $local, $currency, $segment, $LOB, $first_month, $owner) = @{$key_values}; for (@$key_values) { print CURR "@$_,"; # values out to .csv as expected. } print CURR "\n"; $sheet = $book->Worksheets("FTE"); # get focus on the FTE worksheet # calculate the end column of months - month -6 starts in col P # so we need $term + 6 cols added to P. The $range for Excel is specified # as "CR:cr" where CR is the top, left cell of the range, and cr the bottom # right. # # Determine the right-most column = 'P' + 6 + $term my $col = 'P'; print "\$term is @{$term}\n"; # prints 120 as required for(-5..@{$term}) { # but `..' seems to be in scalar context! $col++; print "$col,"; } undef $book; undef $ex; close CURR;