Subject: | Cells alignment in row array may break if null presents |
In order to reduce memory usage, the upstream Spreadsheet::ParseExcel
parser calls the cell handler call-back only when the cell has
something. Thus both leading and in-between nulls may interfer the
alignment of cells in the outcome row array, if the positions of cells
are ignored. An example following:
original sheet w/ null properly aligned array array
w/o alignment
|A1|B1|C1|D1|E1|F1|G1|H1| {A1|B1|C1|D1|E1|F1|G1|H1}
{A1|B1|C1|D1|E1|F1|G1|H1}
| | |C2|D2|E2|F2|G2|H2| {||C2|D2|E2|F2|G2|H2}
{C2|D2|E2|F2|G2|H2}
| | | | |E3|F3|G3|H3| {||||E3|F3|G3|H3}
{E3|F3|G3|H3}
| | | | | | |G4|H4| {||||||G4|H4} {G4|H4}
| |B1|C1|D1|E1|F1|G1|H1| {B1|C1|D1|E1|F1|G1|H1}
{B1|C1|D1|E1|F1|G1|H1}
| | | |D2|E2|F2|G2|H2| {||D2|E2|F2|G2|H2}
{D2|E2|F2|G2|H2}
| | | | | |F3|G3|H3| {||||F3|G3|H3}
{F3|G3|H3}
| | | | | | | |H4| {||||||H4} {H4}
| |B1|C1|D1|E1|F1|G1|H1| {|B1|C1|D1|E1|F1|G1|H1}
{B1|C1|D1|E1|F1|G1|H1}
| | | |D2|E2|F2|G2|H2| {|||D2|E2|F2|G2|H2}
{D2|E2|F2|G2|H2}
|A3|B3| | | |F3|G3|H3| {A3|B3||||F3|G3|H3}
{A3|B3|F3|G3|H3}
|A4|B4|C4|D4| | | |H4| {A4|B4|C4|D4||||H4}
{A4|B4|C4|D4|H4}
The attached diff file tries to reuse the position of cell to build the
row array.
Subject: | Stream.pm.diff |
--- Stream.pm 2011-07-30 03:06:14.000000000 +0800
+++ Stream.pm 2011-07-30 03:06:14.000000000 +0800
@@ -92,13 +92,22 @@
my $f = $self->{SUB};
# Initialize row with first cell
+=begin comment may_misplace
my @row = ($curr_cell);
+=end comment may_misplace
+=cut
+ my @row = ();
+ $row[ $curr_cell->[3] - ( $curr_cell->[0] -> worksheet( $curr_cell->[1] ) -> col_range )[0] ] = $curr_cell;
my $nxt_cell = $f->();
# Collect current row on current worksheet
while ( $nxt_cell && $nxt_cell->[1] == $curr_cell->[1] && $nxt_cell->[2] == $curr_cell->[2] ) {
$curr_cell = $nxt_cell;
+=begin comment may_misplace
push @row, $curr_cell;
+=end comment may_misplace
+=cut
+ $row[ $curr_cell->[3] - ( $curr_cell->[0] -> worksheet( $curr_cell->[1] ) -> col_range )[0] ] = $curr_cell;
$nxt_cell = $f->();
}
$self->{NEXT_CELL} = $nxt_cell;
@@ -112,7 +121,11 @@
my $row = $self->next_row();
return unless $row;
}
+=begin comment may_mistreat
return [ map { $_->[4]->value() } @{$self->{CURR_ROW}} ];
+=end comment may_mistreat
+=cut
+ return [ map { defined $_ ? $_->[4]->value() : $_ } @{$self->{CURR_ROW}} ];
}
sub row_unformatted {
@@ -121,7 +134,11 @@
my $row = $self->next_row();
return unless $row;
}
+=begin comment may_mistreat
return [ map { $_->[4]->unformatted() } @{$self->{CURR_ROW}} ];
+=end comment may_mistreat
+=cut
+ return [ map { defined $_ ? $_->[4]->unformatted() : $_ } @{$self->{CURR_ROW}} ];
}
1;