I also read about Spreadsheet::Read which cannot work with formatted values
What ?
my @row = Spreadsheet::Read::row ($book->[1], 3)
Get full row of formatted values (like $sheet->{A3} .. $sheet->{G3})
poj | [reply] [d/l] |
| [reply] |
Please have a look at the documentation of Spreadsheet::ParseExcel::SaveParser. It does not "edit" your file, it loads and then overwrites your excel file. You will have to find out how to alter the data structure and then do that. I've already shown you approaches to that, but you seem to want to avoid these.
| [reply] |
How simple is your spreadsheet ? Does it have merged cells, borders, colors, formulae, graphics, etc ?. If it doesn't try this program which should create a copy.Then either adapt it for your update or explain some more the problem you have.
#!perl
use strict;
use Spreadsheet::ParseXLSX;
use Excel::Writer::XLSX;
use Data::Dump 'pp';
my $file = 'c://temp//Book1';
my @data=();
read_file($file.'.xlsx');
#pp \@data;
write_file($file.'_copied.xlsx');
sub read_file {
my $file = shift;
print "Reading $file\n";
my $parser = Spreadsheet::ParseXLSX->new();
my $wb1 = $parser->parse($file);
if ( !defined $wb1 ) {
die $parser->error(), ".\n";
}
for my $n ( 1 .. $wb1->worksheet_count() ) {
my $ws = $wb1->worksheet($n-1);
my ( $row_min, $row_max ) = $ws->row_range();
my ( $col_min, $col_max ) = $ws->col_range();
my @tmp = ();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $ws->get_cell( $row, $col );
next unless $cell;
push @tmp,join "\t",$row,$col,$cell->value();
}
}
my $name = $ws->get_name;
print "Reading sheet $n $name\n";
push @data,[$name,\@tmp];
}
}
sub write_file {
my $file = shift;
print "Creating copy workbook $file\n";
my $wb2 = Excel::Writer::XLSX->new( $file );
for my $n (1..@data){
my $name = $data[$n-1][0];
my $ar = $data[$n-1][1];
print "Adding sheet $n $name\n";
my $ws = $wb2->add_worksheet($name);
for (@$ar){
my ($row,$col,$value) = split "\t",$_;
$ws->write( $row, $col, $value );
}
}
$wb2->close();
}
poj
| [reply] [d/l] |