Created
December 23, 2016 18:29
-
-
Save whosgonna/ebcb637f514b3d8f4b53637a973c0517 to your computer and use it in GitHub Desktop.
Created and used "named cells" in a perl created Excel document.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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