I wrote a perl file which opens up a CSV file and removes the first row of the file, and the last column of the file.
What I need to somehow do is save the text from the first row of the file (which I then remove), so as to add it to the top of another sheet in the same workbook. Any ideas?
below is the code, which I run by typing "perl thisFIlename.pl file_being_edited.csv > new_output.txt
Essentially, I output this into a text, then have my xls import that text.
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
my $csv = Text::CSV->new();
my $columns;
while (<>) {
next if ($. == 1);
$csv->parse($_);
my @columns = ($csv->fields());
my $i = pop(@columns);
print join(' ', @columns), "\n";
}
# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
# open Excel file
my $Book = $Excel->Workbooks->Open("c:/location/sheet1.xls");
$Excel->Run("macro1");
$Excel->Run("macro2");
What I need to somehow do is save the text from the first row of the file (which I then remove), so as to add it to the top of another sheet in the same workbook. Any ideas?
below is the code, which I run by typing "perl thisFIlename.pl file_being_edited.csv > new_output.txt
Essentially, I output this into a text, then have my xls import that text.
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
my $csv = Text::CSV->new();
my $columns;
while (<>) {
next if ($. == 1);
$csv->parse($_);
my @columns = ($csv->fields());
my $i = pop(@columns);
print join(' ', @columns), "\n";
}
# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
# open Excel file
my $Book = $Excel->Workbooks->Open("c:/location/sheet1.xls");
$Excel->Run("macro1");
$Excel->Run("macro2");