summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-10-09 10:16:00 -0400
committerJesse Luehrs <doy@tozt.net>2013-10-09 10:16:00 -0400
commit2f2f03f915eaaf9300dcf3587961f43733b7ded7 (patch)
treecbfa49a713ad5930b24ea9ef5c18d6414dee27f4
parent8fc846b02f32f0f701525e356f6544958cd0d43d (diff)
downloadspreadsheet-parsexlsx-2f2f03f915eaaf9300dcf3587961f43733b7ded7.tar.gz
spreadsheet-parsexlsx-2f2f03f915eaaf9300dcf3587961f43733b7ded7.zip
support merged cells (rolaf, #10)
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm24
1 files changed, 24 insertions, 0 deletions
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')