Skip to content

Instantly share code, notes, and snippets.

@whosgonna
Created December 23, 2016 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whosgonna/ebcb637f514b3d8f4b53637a973c0517 to your computer and use it in GitHub Desktop.
Save whosgonna/ebcb637f514b3d8f4b53637a973c0517 to your computer and use it in GitHub Desktop.
Created and used "named cells" in a perl created Excel document.
#!/usr/bin/env perl
use strict;
use warnings;
use Excel::Writer::XLSX;
use Excel::Writer::XLSX::Utility;
## Create the excel document, and add two worksheets, named "Page 1" and
## "Page 2" repectively.
my $wb = Excel::Writer::XLSX->new('Excel_Named_Reference.xlsx');
my $ws1 = $wb->add_worksheet('Page 1');
my $ws2 = $wb->add_worksheet('Page 2');
## Write some data to cell A2, using "Row-Column" notation (row 1, Col 0).
## For most real programming examples using Row-Column is easier to work with.
my $row = 1;
my $col = 0;
$ws1->write( $row, $col,'15.5');
## Get the "Absolute" "A1" style notation of the cell ($A$2)
my $name = xl_rowcol_to_cell( $row, $col, 1, 1 );
## Use the 'define_name' method to assign a static name (NameOfCell) to cell
## A2 on worksheet "Page 1"
$wb->define_name( 'NameOfCell', qq{='Page 1'!$name} );
## Populate cell B2 on sheet "Page 2" with a reference to the value of cell
## A2 on worksheet "Page 1"
$ws2->write('B2', q{=NameOfCell});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment