/usr/share/doc/libspreadsheet-writeexcel-perl/examples/writeA1.pl is in libspreadsheet-writeexcel-perl 2.40-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #!/usr/bin/perl -w
###############################################################################
#
# This is an example of how to extend the Spreadsheet::WriteExcel module.
#
# Code is appended to the Spreadsheet::WriteExcel::Worksheet module by reusing
# the package name. The new code provides a write() method that allows you to
# use Excels A1 style cell references. This is not particularly useful but it
# serves as an example of how the module can be extended without modifying the
# code directly.
#
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
#
use strict;
use Spreadsheet::WriteExcel;
# Create a new workbook called simple.xls and add a worksheet
my $workbook = Spreadsheet::WriteExcel->new("writeA1.xls");
my $worksheet = $workbook->add_worksheet();
# Write numbers or text
$worksheet->write (0, 0, "Hello");
$worksheet->writeA1("A3", "A3" );
$worksheet->writeA1("A5", 1.2345 );
###############################################################################
#
# The following will be appended to the Spreadsheet::WriteExcel::Worksheet
# package.
#
package Spreadsheet::WriteExcel::Worksheet;
###############################################################################
#
# writeA1($cell, $token, $format)
#
# Convert $cell from Excel A1 notation to $row, $col notation and
# call write() on $token.
#
# Returns: return value of called subroutine or -4 for invalid cell
# reference.
#
sub writeA1 {
my $self = shift;
my $cell = shift;
my $col;
my $row;
if ($cell =~ /([A-z]+)(\d+)/) {
($row, $col) = _convertA1($2, $1);
$self->write($row, $col, @_);
} else {
return -4;
}
}
###############################################################################
#
# _convertA1($row, $col)
#
# Convert Excel A1 notation to $row, $col notation. Convert base26 column
# string to a number.
#
sub _convertA1 {
my $row = $_[0];
my $col = $_[1]; # String in AA notation
my @chars = split //, $col;
my $expn = 0;
$col = 0;
while (@chars) {
my $char = uc(pop(@chars)); # LS char first
$col += (ord($char) -ord('A') +1) * (26**$expn);
$expn++;
}
# Convert 1 index to 0 index
$row--;
$col--;
return($row, $col);
}
|