summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-05-25 00:51:10 -0400
committerJesse Luehrs <doy@tozt.net>2016-05-25 00:51:10 -0400
commit55fe973c525895a6b4516618cae5ec77c748938c (patch)
treef54b8ee528c291604548ad0def1a00423f96c97e
parent88153ff1602004d42bf9e8220c8a8d114b591cab (diff)
downloadspreadsheet-parsexlsx-55fe973c525895a6b4516618cae5ec77c748938c.tar.gz
spreadsheet-parsexlsx-55fe973c525895a6b4516618cae5ec77c748938c.zip
handling merged cells doesn't actually require two full passes
parsing the full sheet can be quite slow, and we can just fix things up directly after a single pass instead
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm21
1 files changed, 8 insertions, 13 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index 6cf5486..c38cfc2 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -213,6 +213,8 @@ sub _parse_sheet {
my $default_row_height = 15;
my $default_column_width = 10;
+ my %cells;
+
my $sheet_xml = $self->_new_twig(
twig_roots => {
#XXX need a fallback here, the dimension tag is optional
@@ -353,16 +355,6 @@ sub _parse_sheet {
$twig->purge;
},
- }
- );
-
- $sheet_xml->parse( $sheet_file );
-
- # 2nd pass: cell/row building is dependent on having parsed the merge definitions
- # beforehand.
-
- $sheet_xml = $self->_new_twig(
- twig_roots => {
's:sheetData/s:row' => sub {
my ( $twig, $row_elt ) = @_;
@@ -417,7 +409,6 @@ sub _parse_sheet {
my $format_idx = $cell->att('s') || 0;
my $format = $sheet->{_Book}{Format}[$format_idx];
die "unknown format $format_idx" unless $format;
- $format->{Merged} = $merged_cells{"$row;$col"};
# see the list of built-in formats below in _parse_styles
# XXX probably should figure this out from the actual format string,
@@ -430,7 +421,7 @@ sub _parse_sheet {
my $cell = Spreadsheet::ParseExcel::Cell->new(
Val => $val,
Type => $long_type,
- Merged => $format->{Merged},
+ Merged => undef, # fix up later
Format => $format,
FormatNo => $format_idx,
($formula
@@ -441,17 +432,21 @@ sub _parse_sheet {
$cell->{_Value} = $sheet->{_Book}{FmtClass}->ValFmt(
$cell, $sheet->{_Book}
);
+ $cells{"$row;$col"} = $cell;
$sheet->{Cells}[$row][$col] = $cell;
}
$twig->purge;
},
-
}
);
$sheet_xml->parse( $sheet_file );
+ for my $key (keys %merged_cells) {
+ $cells{$key}{Merged} = 1 if $cells{$key};
+ }
+
if ( ! $sheet->{Cells} ){
$sheet->{MaxRow} = $sheet->{MaxCol} = -1;
}