Subject: | Spreadsheet::ParseExcel::SaveParser does not handle merged cells correctly |
Dear Gábor,
S::PE::SaveParser uses S::WriteExcel's deprecated set_merge method
instead of the newer merge_range method.
This causes merged cells not to be merged in the destination file.
Please find attached a diff file to correct this problem. Note that it
also adds a 'use Spreadsheet::ParseExcel' at the top of the file, as
reported by another user.
I am using version 0.06 of this module (distribution version is 0.32).
Best regards,
Julio Fraire
Subject: | merged_areas.diff |
--- SaveParser.pm.bak 2008-02-04 10:04:24.000000000 -0600
+++ SaveParser.pm 2008-02-07 11:55:20.000000000 -0600
@@ -11,6 +11,7 @@
use strict;
use warnings;
+use Spreadsheet::ParseExcel;
use base 'Spreadsheet::ParseExcel::Workbook';
our $VERSION = '0.06';
@@ -114,6 +115,17 @@
for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) {
my $oWkS = $oBook->{Worksheet}[$iSheet];
my $oWrS = $oWrEx->addworksheet($oWkS->{Name});
+
+ # Merged areas
+ foreach my $area ( @{ $oWkS->{MergedArea} } ) {
+
+ my $cell = $oWkS->Cell($area->[0], $area->[1]);
+ my $oFmtN = $oWrEx->addformat();
+ $oFmtN->copy($hFmt{$cell->{FormatNo}});
+ $oWrS->merge_range( @$area, $cell->{Val}, $oFmtN, utf8::is_utf8($cell->{Val}));
+ }
+
+
#Landscape
if(!$oWkS->{Landscape}) { # Landscape (0:Horizontal, 1:Vertical)
$oWrS->set_landscape();
@@ -123,12 +135,12 @@
}
#Protect
if(defined $oWkS->{Protect}) { # Protect ('':NoPassword, Password:Password)
- if ($oWkS->{Protect} ne '') {
- $oWrS->protect($oWkS->{Protect});
- }
- else {
- $oWrS->protect();
- }
+ if ($oWkS->{Protect} ne '') {
+ $oWrS->protect($oWkS->{Protect});
+ }
+ else {
+ $oWrS->protect();
+ }
}
if(($oWkS->{FitWidth}==1) and ($oWkS->{FitHeight}==1)) {
# Pages on fit with width and Heigt
@@ -215,17 +227,9 @@
my $oWkC = $oWkS->{Cells}[$iR][$iC];
if($oWkC) {
- if($oWkC->{Merged}) {
- my $oFmtN = $oWrEx->addformat();
- $oFmtN->copy($hFmt{$oWkC->{FormatNo}});
- $oFmtN->set_merge(1);
- $oWrS->write($iR , $iC, $oBook->{FmtClass}->TextFmt($oWkC->{Val}, $oWkC->{Code}),
- $oFmtN);
- }
- else {
- $oWrS->write($iR , $iC, $oBook->{FmtClass}->TextFmt($oWkC->{Val}, $oWkC->{Code}),
- $hFmt{$oWkC->{FormatNo}});
- }
+ next if $oWkC->{Merged};
+ $oWrS->write($iR , $iC, $oBook->{FmtClass}->TextFmt($oWkC->{Val}, $oWkC->{Code}),
+ $hFmt{$oWkC->{FormatNo}});
}
}
}