in reply to Reading Variables in Excel Spreadsheet

Try

#!perl use strict; use Win32::OLE 'in'; use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # Die on Errors. # config my $dir = 'c:/temp/'; my $specfile = 'names.xlsx'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{DisplayAlerts} = 0; #$Excel->{Visible} = 1; my $Book = $Excel->Workbooks->Open($dir.$specfile); # create named range my $range = $Book->Worksheets(1)->Range("A1"); $range->{'Name'} = "Any_name"; # no spaces # show named ranges for my $nm (in $Book->Names){ printf "%s %s\n", $nm->{'Name'},$nm->{'Value'}; } # close $Book->Close(); $Excel->Quit(); undef $Book; undef $Excel;
poj

Replies are listed 'Best First'.
Re^2: Reading Variables in Excel Spreadsheet
by Anonymous Monk on Jan 15, 2018 at 15:46 UTC
    I used your Perl on the spreadsheet with the variables defined.

    Cell B1 was defined as depth and had the value of 559
    Cell B2 was defined as height snd had the value of 560
    Cell B3 was defined as Width and had the value of 590?

    I got quite a lot of output but this well be because I simply removed cells to leave just a few to consider.
    In this output I found the following
    depth =CALC!$B$1
    height =CALC!$B$2
    width =CALC!$B$3

    This seems usable since it effective says that the three variaibles depth, height and width are in the 3 cells B1, B2 and B3.
    I think I can use the cell references to 'read' the values but I wondered what the most effect way of doing this.
    Some clues will be appreciated

      You can read the values using the name

      for my $nm (in $Book->Names){ my $rng = $ws->Range($nm); printf "%s %s\n", $nm->{'Name'},$rng->{'Value'}; }
      poj
        Many thanks but there is something not quite right.
        In the 2nd line there is $ws. What is this variable since it is not defined in the original Perl?