2

I have excel file, which has TextBox control at one of its sheets with the name TextBox1. And there's some text in this TextBox, that I need to extract. I'm trying to get this text with a help of Perl, however I have no idea how to reference TextBox Control.

Here is my code:

use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;    # die on errors...
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
    || Win32::OLE->new( 'Excel.Application', 'Quit' );    # get already active Excel
                                                          # application or open new
my $Book  = $Excel->Workbooks->Open("25.xls");            # open Excel file
my $Sheet = $Book->Worksheets('Test1');                   # select worksheet number 1
my $array = $Sheet->Range("TextBox1")->{'Value'};         # get the contents
$Book->Close;

foreach my $ref_array (@$array) {                         # loop through the array
                                                          # referenced by $array
    foreach my $scalar (@$ref_array) {
        print "$scalar\t";
    }
    print "\n";
}

enter image description here

Please advise how to reference Text Box control in Perl.

Miller
  • 34,962
  • 4
  • 39
  • 60
MaterialGirl
  • 363
  • 2
  • 10
  • 22
  • 1
    Veronica :), Haven't windows installed, so can't try OLE but you can use the [Data::Dumper](https://metacpan.org/pod/Data::Dumper) module to show what is the content of the `$sheet` and step-by-step - deeper... – clt60 Sep 09 '14 at 16:31

1 Answers1

0

This is not the appropriate answer. But can not post comment yet! so, hope this helps in referencing textbox.

link : suggestion about how to access textbox inside a worksheet in excel

dont know about perl. But from Excel object model point of view:

Worksheetname.Textboxname.Text 

or

Worksheetname.OLEObjects("Textboxname").Object.Text
Community
  • 1
  • 1
ZAT
  • 1,347
  • 7
  • 10