Subject: | Hyperlinks are always formatted as text |
As Requested:
Hi, I'm using this module and I needed to hyperlink numbers, so i
added a method _write_guess after _write, and put the checks for
blank, string, formula and number in there. Then I changed writre and
the 3 _write_url methods to call _write_guess so that numbers would be
numbers not string. The numbers are still by default formatted just
blue underline, but I couldn't see a particulary painless way of
changing that.
This also works for formats as far as I can see.
--- Worksheet.pm.old 2005-09-07 13:13:41.000000000 +0100
+++ Worksheet.pm 2005-09-07 13:52:59.000000000 +0100
@@ -1092,14 +1092,6 @@
if (ref $token eq "ARRAY") {
return $self->write_row(@_);
}
- # Match integer with leading zero(s)
- elsif ($self->{_leading_zeros} and $token =~ /^0\d+$/) {
- return $self->write_string(@_);
- }
- # Match number
- elsif ($token =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) {
- return $self->write_number(@_);
- }
# Match http, https or ftp URL
elsif ($token =~ m|^[fh]tt?ps?://|) {
return $self->write_url(@_);
@@ -1111,6 +1103,36 @@
# Match internal or external sheet link
elsif ($token =~ m[^(?:in|ex)ternal:]) {
return $self->write_url(@_);
+ } else {
+ return $self->_write_guess(@_);
+ }
+
+}
+
+
+###############################################################################
+#
+# _write_guess($row, $col, $token, $format)
+#
+# Parse $token and call appropriate write method. $row and $column are zero
+# indexed. $format is optional.
+#
+# Returns: return value of called subroutine
+#
+#
+sub _write_guess {
+
+ my $self = shift;
+
+ my $token = $_[2];
+
+ # Match integer with leading zero(s)
+ if ($self->{_leading_zeros} and $token =~ /^0\d+$/) {
+ return $self->write_string(@_);
+ }
+ # Match number
+ elsif ($token =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) {
+ return $self->write_number(@_);
}
# Match formula
elsif ($token =~ /^=/) {
@@ -1991,7 +2013,7 @@
# Write the visible label using the write_string() method.
$str = $url unless defined $str;
- my $str_error = $self->write_string($row1, $col1, $str, $xf);
+ my $str_error = $self->_write_guess($row1, $col1, $str, $xf);
return $str_error if $str_error == -2;
@@ -2063,7 +2085,7 @@
# Write the visible label
$str = $url unless defined $str;
- my $str_error = $self->write_string($row1, $col1, $str, $xf);
+ my $str_error = $self->_write_guess($row1, $col1, $str, $xf);
return $str_error if $str_error == -2;
@@ -2146,7 +2168,7 @@
# Write the visible label
($str = $url) =~ s[\#][ - ] unless defined $str;
- my $str_error = $self->write_string($row1, $col1, $str, $xf);
+ my $str_error = $self->_write_guess($row1, $col1, $str, $xf);
return $str_error if $str_error == -2;
@@ -4286,3 +4308,4 @@
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
+