use Spreadsheet::ParseExcel::Simple;
use Data::Dumper;
my $xls = Spreadsheet::ParseExcel::Simple->read('excel.xls');
foreach my $sheet ($xls->sheets) {
die Dumper $sheet;
#while ($sheet->has_data) {
# my @data = $sheet->next_row;
#}
}
Take a look at the fields AlignH, AlignV and Merged. If Merged=1 you can have a value or no value.
So, in order to keep on using Spreadsheet::ParseExcel::Simple I added a small unmerge() function that removes the span's:
use Spreadsheet::ParseExcel::Simple;
my $xls = Spreadsheet::ParseExcel::Simple->read('excel.xls');
foreach my $sheet ($xls->sheets) {
#unmerge
unmerge($sheet->{sheet});
while ($sheet->has_data) {
my @data = $sheet->next_row;
print join("\t", @data),"\n";
}
}
sub unmerge{
my($oWkS) =@_;
print "--------- SHEET:", $oWkS->{Name}, "\n";
for(my $iR = $oWkS->{MinRow} ;
defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++)
+ {
for(my $iC = $oWkS->{MinCol} ;
defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxC
+ol} ; $iC++) {
$oWkC = $oWkS->{Cells}[$iR][$iC];
next unless $oWkC;
if($oWkC->is_merged){
if($oWkC->Value){
print "COPY V=$oWkC->{Format}->{AlignV} H=$oWkC->{
+Format}->{AlignH}\n";
for my $i (1..$oWkC->{Format}->{AlignV}){
print "ADDV [$iR+$i][$iC] \n";
$oWkS->{Cells}[$iR+$i][$iC]->{_Value} = $oWkC-
+>Value;
$oWkS->{Cells}[$iR+$i][$iC]->{Merged}=0;
}
for my $i (1..$oWkC->{Format}->{AlignH}){
print "ADDH [$iR][$iC+$i] \n";
$oWkS->{Cells}[$iR][$iC+$i]->{_Value} = $oWkC-
+>Value;
$oWkS->{Cells}[$iR][$iC+$i]->{Merged}=0;
}
}
}
print "( $iR , $iC ) ==", $oWkC->Value, " ", $oWkC->{Merge
+d},"\n";
}
}
}
This should copy/clone your spanned data... while still being able to use Simple...
in my case, my output was:
--------- SHEET:Sheet1
COPY V=2 H=0
ADDV [0+1][0]
ADDV [0+2][0]
( 0 , 0 ) ==cat 1
( 0 , 1 ) ==Fluffy
( 1 , 0 ) ==cat 0
( 1 , 1 ) ==Vera
( 2 , 0 ) ==cat 0
( 2 , 1 ) ==Manxie
cat Fluffy
cat Vera
cat Manxie
edit: can you send me your xls example where the cell is at the second row, Libreoffice forces the data from the rightmost/topmost...
edit2: Ok, merged cells that already had a value, and my subroutine dies because the AlignH/AlignV are messed up. This will need some more tinkering before it works properly. (but need to sleep now) |