From 4f7a8fec04501efb2cf1c7b1789d74ca8a3bf757 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 13 May 2013 16:53:03 -0500 Subject: selection and cell sizes --- lib/Spreadsheet/ParseXLSX.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 27e8339..2972c5f 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -82,6 +82,10 @@ sub _parse_workbook { $workbook->{Worksheet} = \@sheets; $workbook->{SheetCount} = scalar(@sheets); + my ($node) = $files->{workbook}->find_nodes('//workbookView'); + my $selected = $node->att('activeTab'); + $workbook->{SelectedSheet} = defined($selected) ? 0+$selected : 0; + return $workbook; } @@ -131,7 +135,34 @@ sub _parse_sheet { ); } - # ... + my @column_widths; + my @row_heights; + + my ($format) = $sheet_xml->find_nodes('//sheetFormatPr'); + my $default_row_height = $format->att('defaultRowHeight') || 15; + my $default_column_width = $format->att('baseColWidth') || 10; + + for my $col ($sheet_xml->find_nodes('//col')) { + $column_widths[$col->att('min') - 1] = $col->att('width'); + } + + for my $row ($sheet_xml->find_nodes('//row')) { + $row_heights[$row->att('r') - 1] = $row->att('ht'); + } + + $sheet->{DefRowHeight} = 0+$default_row_height; + $sheet->{DefColWidth} = 0+$default_column_width; + $sheet->{RowHeight} = [ + map { defined $_ ? 0+$_ : 0+$default_row_height } @row_heights + ]; + $sheet->{ColWidth} = [ + map { defined $_ ? 0+$_ : 0+$default_column_width } @column_widths + ]; + + my ($selection) = $sheet_xml->find_nodes('//selection'); + my $cell = $selection->att('activeCell'); + + $sheet->{Selection} = [ $self->_cell_to_row_col($cell) ]; } sub _parse_shared_strings { -- cgit v1.2.3-54-g00ecf