summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-11-06 10:58:48 -0500
committerJesse Luehrs <doy@tozt.net>2013-11-06 11:03:00 -0500
commit59667433810abb7406139bc858edfc793036a269 (patch)
treeb80f1af282edb59e73bcbcf55f6a1a1e472fd450
parentec0983d61ddd729e62577102fd6af05d833b366a (diff)
downloadspreadsheet-parsexlsx-59667433810abb7406139bc858edfc793036a269.tar.gz
spreadsheet-parsexlsx-59667433810abb7406139bc858edfc793036a269.zip
implement the inlineStr cell type
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm25
-rw-r--r--t/bug-12.t24
-rw-r--r--t/data/bug-12.xlsxbin0 -> 4970 bytes
3 files changed, 37 insertions, 12 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index 0b1b7ad..da53bc3 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -92,7 +92,8 @@ sub _parse_workbook {
$workbook->{FormatStr} = $styles->{FormatStr};
$workbook->{Font} = $styles->{Font};
- $workbook->{PkgStr} = $self->_parse_shared_strings($files->{strings});
+ $workbook->{PkgStr} = $self->_parse_shared_strings($files->{strings})
+ if $files->{strings};
# $workbook->{StandardWidth} = ...;
@@ -169,10 +170,11 @@ sub _parse_sheet {
for my $cell (@cells) {
my ($row, $col) = $self->_cell_to_row_col($cell->att('r'));
- my $val = $cell->first_child('v')
- ? $cell->first_child('v')->text
- : undef;
my $type = $cell->att('t') || 'n';
+ my $val_xml = $type eq 'inlineStr'
+ ? $cell->first_child('is')->first_child('t')
+ : $cell->first_child('v');
+ my $val = $val_xml ? $val_xml->text : undef;
my $long_type;
if (!defined($val)) {
@@ -197,7 +199,7 @@ sub _parse_sheet {
elsif ($type eq 'e') {
$long_type = 'Text';
}
- elsif ($type eq 'str') {
+ elsif ($type eq 'str' || $type eq 'inlineStr') {
$long_type = 'Text';
}
else {
@@ -545,12 +547,9 @@ sub _extract_files {
$zip,
$self->_rels_for($wb_name)
);
- my $strings_xml = $self->_parse_xml(
- $zip,
- $path_base . ($wb_rels->find_nodes(
- qq<//Relationship[\@Type="$type_base/sharedStrings"]>
- ))[0]->att('Target')
- );
+ my ($strings_xml) = map {
+ $self->_parse_xml($zip, $path_base . $_->att('Target'))
+ } $wb_rels->find_nodes(qq<//Relationship[\@Type="$type_base/sharedStrings"]>);
my $styles_xml = $self->_parse_xml(
$zip,
$path_base . ($wb_rels->find_nodes(
@@ -568,10 +567,12 @@ sub _extract_files {
return {
workbook => $wb_xml,
- strings => $strings_xml,
styles => $styles_xml,
sheets => \%worksheet_xml,
themes => \%themes_xml,
+ ($strings_xml
+ ? (strings => $strings_xml)
+ : ()),
};
}
diff --git a/t/bug-12.t b/t/bug-12.t
new file mode 100644
index 0000000..0af7a6a
--- /dev/null
+++ b/t/bug-12.t
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Spreadsheet::ParseXLSX;
+
+my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/bug-12.xlsx');
+is($wb->worksheet_count, 1);
+
+my $ws = $wb->worksheet(0);
+my ($rmin, $rmax) = $ws->row_range;
+my ($cmin, $cmax) = $ws->col_range;
+is($rmin, 0);
+is($rmax, 0);
+is($cmin, 0);
+is($cmax, 3);
+
+is($ws->get_cell(0, 0)->value, 7);
+is($ws->get_cell(0, 1)->value, 3);
+is($ws->get_cell(0, 2)->value, 30);
+is($ws->get_cell(0, 3)->value, 'Kuku');
+
+done_testing;
diff --git a/t/data/bug-12.xlsx b/t/data/bug-12.xlsx
new file mode 100644
index 0000000..a92a544
--- /dev/null
+++ b/t/data/bug-12.xlsx
Binary files differ