Hi guys,
I have .xls files which contain around 8k lines ...I want to append one more line at the end... So either i need a function to append a line or the no. Of rows present in the file as I don't know how long a file can be.
There is nothing in WriteExcel to find total no of rows in a file.
Thanks for your suggestions friends...I'm stuck here. I don't know how to proceed.
| [reply] |
Here is an example of a solution:
use Modern::Perl '2014';
use Spreadsheet::ParseExcel::Simple;
use Spreadsheet::WriteExcel;
my $xls_in = Spreadsheet::ParseExcel::Simple->read('./spreadsheet_in.
+xls');
my $xls_out = Spreadsheet::WriteExcel->new('./spreadsheet_out.xls');
foreach my $sheet ( $xls_in->sheets ) {
my $active_sheet = $xls_out->add_worksheet();
my @sheet_data;
while ( $sheet->has_data ) {
my @data = $sheet->next_row;
push @sheet_data, \@data;
}
push @sheet_data, ['This data is added at the end'];
$active_sheet->write_col( 0, 0, \@sheet_data );
}
$xls_out->close();
This is not a complete solution: for instance, it does not pick up any formatting or names of the sheets. If you want that, you cannot use Spreadsheet::ParseExcel::Simple but you will have to use Spreadsheet::ParseExcel.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
| [reply] [d/l] [select] |