Here is my program:
#!/usr/bin/perl
use Excel::Writer::XLSX;
use Excel::Writer::XLSX::Utility;
my $wb = new Excel::Writer::XLSX('mywb.xlsx');
my $sheetname = '110910';
my $ws = $wb->add_worksheet("$sheetname");
my $wsrow = 0;
$ws->write( $wsrow, 3, [ 'Some Factor' ] );
$ws->write( $wsrow, 4, [ 1.03 ] );
$wb->define_name('Some_Factor', "=$sheetname!" . AbsCell( $wsrow++, 4 ));
$ws->write( $wsrow++,0, ['Fund', 'ORGN', 'Budget' ] );
$ws->write( $wsrow++,0,[ '11', '4100', '=300*Some_Factor' ] );
$ws->write( $wsrow++,0,[ '11', '4105', '=1000*Some_Factor' ] );
$wb->close;
# Change from relative reference (BI31) to absolute ($BI$31)
sub AbsCell {
my ( $row, $col ) = @_;
my $rowcol = xl_rowcol_to_cell( $row, $col );
my $numcol = 1;
if ($rowcol =~ /[[:alpha:]]*(\d*)/) {
$numcol = index($rowcol, $1);
}
return '$' . substr($rowcol,0,$numcol) . '$' . substr($rowcol,$numcol);
}
If the sheetname is something alpha, like 'ops' it works. However, as shown above the define_name is not working, and references to it get an error. Also, when opening the workbook I have to CTRL_SHIFT_F9 to get it calculated. Am I coding this wrong? Is there a way to quote the sheet name so it is not considered a number?
Marvin Budd