summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-08-29 15:41:59 -0400
committerJesse Luehrs <doy@tozt.net>2013-08-29 15:41:59 -0400
commit4e03d41c19ee0f70f076934455844fe40b122f3f (patch)
treea4b39266bc12de61da035630c9674607b4ba6ce6
parent5ff1728282b6bccaa553f97bf4b8d1fc121f92c3 (diff)
downloadspreadsheet-parsexlsx-4e03d41c19ee0f70f076934455844fe40b122f3f.tar.gz
spreadsheet-parsexlsx-4e03d41c19ee0f70f076934455844fe40b122f3f.zip
fix this algorithm again
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm9
-rw-r--r--t/cell-to-row-col.t27
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index 8159fa8..209ae6f 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -575,9 +575,12 @@ sub _cell_to_row_col {
my ($col, $row) = $cell =~ /([A-Z]+)([0-9]+)/;
- (my $ncol = $col) =~ tr/A-Z/1-9A-Q/;
- $ncol = POSIX::strtol($ncol, 27);
- $ncol -= 1;
+ my $ncol = 0;
+ for my $char (split //, $col) {
+ $ncol *= 26;
+ $ncol += ord($char) - ord('A') + 1;
+ }
+ $ncol = $ncol - 1;
my $nrow = $row - 1;
diff --git a/t/cell-to-row-col.t b/t/cell-to-row-col.t
new file mode 100644
index 0000000..d2ecbaa
--- /dev/null
+++ b/t/cell-to-row-col.t
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Spreadsheet::ParseXLSX;
+
+my %tests = (
+ A1 => [0, 0],
+ Z3 => [2, 25],
+ AA5 => [4, 26],
+ IV256 => [255, 255],
+ ZZ10 => [9, 701],
+ AAA8 => [7, 702],
+ XFD22 => [21, 16383],
+);
+
+for my $cell (sort keys %tests) {
+ # XXX not public API, but i'm lazy
+ is_deeply(
+ [ Spreadsheet::ParseXLSX->_cell_to_row_col($cell) ],
+ $tests{$cell},
+ "correct value for $cell"
+ );
+}
+
+done_testing;