From 2f2f03f915eaaf9300dcf3587961f43733b7ded7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 9 Oct 2013 10:16:00 -0400 Subject: support merged cells (rolaf, #10) --- lib/Spreadsheet/ParseXLSX.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 4f28376..0b1b7ad 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -147,6 +147,26 @@ sub _parse_sheet { $sheet->{MaxCol} = -1; } + my @merged_cells; + for my $merge_area ($sheet_xml->find_nodes('//mergeCells/mergeCell')) { + if (my $ref = $merge_area->att('ref')) { + my ($topleft, $bottomright) = $ref =~ /([^:]+):([^:]+)/; + + my ($toprow, $leftcol) = $self->_cell_to_row_col($topleft); + my ($bottomrow, $rightcol) = $self->_cell_to_row_col($bottomright); + + push @{ $sheet->{MergedArea} }, [ + $toprow, $leftcol, + $bottomrow, $rightcol, + ]; + for my $row ($toprow .. $bottomrow) { + for my $col ($leftcol .. $rightcol) { + push(@merged_cells, [$row, $col]); + } + } + } + } + for my $cell (@cells) { my ($row, $col) = $self->_cell_to_row_col($cell->att('r')); my $val = $cell->first_child('v') @@ -186,6 +206,9 @@ sub _parse_sheet { my $format_idx = $cell->att('s') || 0; my $format = $sheet->{_Book}{Format}[$format_idx]; + $format->{Merged} = !!grep { + $row == $_->[0] && $col == $_->[1] + } @merged_cells; # see the list of built-in formats below in _parse_styles # XXX probably should figure this out from the actual format string, @@ -197,6 +220,7 @@ sub _parse_sheet { my $cell = Spreadsheet::ParseExcel::Cell->new( Val => $val, Type => $long_type, + Merged => $format->{Merged}, Format => $format, FormatNo => $format_idx, ($cell->first_child('f') -- cgit v1.2.3-54-g00ecf