diff --git a/lib/Excel/Writer/XLSX/Utility.pm b/lib/Excel/Writer/XLSX/Utility.pm index 4f3434c5..d430e93c 100644 --- a/lib/Excel/Writer/XLSX/Utility.pm +++ b/lib/Excel/Writer/XLSX/Utility.pm @@ -243,8 +243,9 @@ sub quote_sheetname { $needs_quoting = 1; } - # Rule 3. Sheet names must not be a valid A1 style cell reference. - # Valid means that the row and column values are within Excel limits. + # Rule 3. Sheet names must not be a valid A1 style cell reference. Valid + # means that the row and column range values must also be within Excel + # row and column limits. elsif ( $uc_sheetname =~ /^([A-Z]{1,3}\d+)$/ ) { my ( $row, $col ) = xl_cell_to_rowcol( $1 ); @@ -255,20 +256,23 @@ sub quote_sheetname { } # Rule 4. Sheet names must not *start* with a valid RC style cell - # reference. Valid means that the row and column values are within - # Excel limits. - - # Rule 4a. Check for some single R/C references. - elsif ($uc_sheetname eq "R" - || $uc_sheetname eq "C" - || $uc_sheetname eq "RC" ) - { - $needs_quoting = 1; - + # reference. Other characters after the valid RC reference are ignored + # by Excel. Valid means that the row and column range values must also + # be within Excel row and column limits. + # + # Note: references without trailing characters like R12345 or C12345 are + # caught by Rule 3. Negative references like R-12345 are caught by Rule 1 + # due to the dash. + + # Rule 4a. Check for sheet names that start with R1 style references. + elsif ( $uc_sheetname =~ /^R(\d+)/ ) { + my $row = $1; + if ( $row > 0 && $row <= $row_max ) { + $needs_quoting = 1; + } } - # Rule 4b. Check for C1 or RC1 style references. References without - # trailing characters (like C12345) are caught by Rule 3. + # Rule 4b. Check for sheet names that start with C1 or RC1 style elsif ( $uc_sheetname =~ /^R?C(\d+)/ ) { my $col = $1; if ( $col > 0 && $col <= $col_max ) { @@ -276,39 +280,25 @@ sub quote_sheetname { } } - # Rule 4c. Check for R1C1 style references where both the number - # ranges are optional. Note that only 1 of the number ranges is - # required to be valid. - elsif ( $uc_sheetname =~ /^R(\d+)?C(\d+)?/ ) { - if ( defined $1 ) { - my $row = $1; - if ( $row > 0 && $row <= $row_max ) { - $needs_quoting = 1; - } - } - - if ( defined $2 ) { - my $col = $1; - if ( $col > 0 && $col <= $col_max ) { - $needs_quoting = 1; - } - } + # Rule 4c. Check for some single R/C references. + elsif ($uc_sheetname eq "R" + || $uc_sheetname eq "C" + || $uc_sheetname eq "RC" ) + { + $needs_quoting = 1; } } - if ( $needs_quoting ) { # Double quote any single quotes. $sheetname =~ s/'/''/g; $sheetname = q(') . $sheetname . q('); } - return $sheetname; } - ############################################################################### # # xl_inc_row($string)