From 6d7982ec511aeb1a47c1fed803869bd568055893 Mon Sep 17 00:00:00 2001 From: FL Date: Wed, 18 Jun 2014 05:11:40 +0000 Subject: Correct locked cell detection (no information means locked). --- lib/Spreadsheet/ParseXLSX.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index d5f7781..77e83e7 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -515,7 +515,7 @@ sub _parse_styles { Lock => $protection ? $protection->att('locked') - : 0, + : 1, Hidden => $protection ? $protection->att('hidden') : 0, -- cgit v1.2.3-54-g00ecf From d72a257f454b8b1d3ad93cde2a43f37df4f2ddd7 Mon Sep 17 00:00:00 2001 From: FL Date: Sat, 5 Jul 2014 12:08:53 +0000 Subject: Improve locked cell detection for cells with hidden formulas. Add test for locked cell detection. --- lib/Spreadsheet/ParseXLSX.pm | 2 +- t/bug-lock.t | 26 ++++++++++++++++++++++++++ t/data/bug-lock.xlsx | Bin 0 -> 8480 bytes 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 t/bug-lock.t create mode 100644 t/data/bug-lock.xlsx diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 77e83e7..d20d734 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -513,7 +513,7 @@ sub _parse_styles { Font => $font[$_->att('fontId')], FmtIdx => 0+$_->att('numFmtId'), - Lock => $protection + Lock => $protection && defined $protection->att('locked') ? $protection->att('locked') : 1, Hidden => $protection diff --git a/t/bug-lock.t b/t/bug-lock.t new file mode 100644 index 0000000..142d003 --- /dev/null +++ b/t/bug-lock.t @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Spreadsheet::ParseXLSX; + +my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/bug-lock.xlsx'); +my $ws = $wb->worksheet(0); + +my $b1 = $ws->get_cell(0, 0); +ok($b1->get_format->{Lock}); + +my $b2 = $ws->get_cell(1, 0); +ok(!$b2->get_format->{Lock}); + +my $b3 = $ws->get_cell(2, 0); +ok($b3->get_format->{Lock}); + +my $b4 = $ws->get_cell(3, 0); +ok(!$b4->get_format->{Lock}); + +my $b5 = $ws->get_cell(4, 0); +ok($b5->get_format->{Lock}); + +done_testing; diff --git a/t/data/bug-lock.xlsx b/t/data/bug-lock.xlsx new file mode 100644 index 0000000..bf16fdb Binary files /dev/null and b/t/data/bug-lock.xlsx differ -- cgit v1.2.3-54-g00ecf From 31add70244e61a269db8c69bbd2d2042c5d7d4f5 Mon Sep 17 00:00:00 2001 From: FL Date: Sat, 5 Jul 2014 15:11:37 +0000 Subject: Fix bug-15 test: (merged) cell B2 of the Format sheet is locked. --- t/bug-15.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/bug-15.t b/t/bug-15.t index 47322e8..4c7710a 100644 --- a/t/bug-15.t +++ b/t/bug-15.t @@ -13,7 +13,7 @@ ok(exists $b2->get_format->{Hidden}); ok(exists $b2->get_format->{Lock}); ok($b2->get_format->{IgnoreProtection}); ok(!$b2->get_format->{Hidden}); -ok(!$b2->get_format->{Lock}); +ok($b2->get_format->{Lock}); my $b3 = $ws->get_cell(2, 1); ok(exists $b3->get_format->{Hidden}); -- cgit v1.2.3-54-g00ecf From 5bfde2e914636f99e5994c843dd158f6804e5db5 Mon Sep 17 00:00:00 2001 From: FL Date: Sat, 5 Jul 2014 15:37:18 +0000 Subject: Add support for optional $formatter argument in parse method. --- lib/Spreadsheet/ParseXLSX.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index d20d734..b7346e7 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -33,17 +33,18 @@ sub new { bless {}, shift; } -=method parse($file) +=method parse($file, $formatter) Parses an XLSX file. Parsing errors throw an exception. C<$file> can be either a filename or an open filehandle. Returns a L instance containing the parsed data. +The C<$formatter> argument is an optional formatter class as described in L. =cut sub parse { my $self = shift; - my ($file) = @_; + my ($file, $formatter) = @_; my $zip = Archive::Zip->new; my $workbook = Spreadsheet::ParseExcel::Workbook->new; @@ -62,12 +63,12 @@ sub parse { die "Argument to 'new' must be a filename or open filehandle"; } - return $self->_parse_workbook($zip, $workbook); + return $self->_parse_workbook($zip, $workbook, $formatter); } sub _parse_workbook { my $self = shift; - my ($zip, $workbook) = @_; + my ($zip, $workbook, $formatter) = @_; my $files = $self->_extract_files($zip); @@ -81,7 +82,7 @@ sub _parse_workbook { $workbook->{Flag1904} = $properties->att('date1904') ? 1 : 0; - $workbook->{FmtClass} = Spreadsheet::ParseExcel::FmtDefault->new; # XXX + $workbook->{FmtClass} = $formatter || Spreadsheet::ParseExcel::FmtDefault->new; my $themes = $self->_parse_themes((values %{ $files->{themes} })[0]); # XXX -- cgit v1.2.3-54-g00ecf