stavelot has asked for the wisdom of the Perl Monks concerning the following question:
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->Shapes("TextBox1")->{"Caption"}; ; # get the conte +nts $Book->Close; foreach my $ref_array (@$array) { # loop through the array # referenced by $array foreach my $scalar (@$ref_array) { print "$scalar\t"; } print "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Text Box control in Excel - how to reference in Perl
by jkeenan1 (Deacon) on Sep 09, 2014 at 23:15 UTC | |
Have you considered Spreadsheet::ParseExcel? Thank you very much.
Jim Keenan
| [reply] |
|
Re: Text Box control in Excel - how to reference in Perl
by thanos1983 (Parson) on Sep 09, 2014 at 23:50 UTC | |
Hello stavelot, I am not expert of Excel files, in fact this is my second attempt to play around with them, but it seems that the desired output of your task can be done with a few simple steps. I am using Unix OS so I am not able to use your modules Win32::OLE qw(in with) etc. but my solution is generic so it also work on Windows OS. Explanation, I am using the Excel::Writer::XLSX::Shape as a module to create the shape insert the data and then extract them. Take a look it has many interesting functions on how to modify the shape, I think you will find it interesting. You do not need to use the module to create any shapes since you already have the shape on your excel sheet, but it was necessary for me to replicate your working environment. I simply use Data::Dumper a very useful module that can print arrays, hashes, ref hashes etc. So I just dump the output to see the location of the text and all the settings of the shape. Then as a second step I just print the hash ref with the desired information and Voila. Sample of working code:
Here is the output:
As you can see with the hash we got (Hello World) it is printed in two lines because of the \n new line character. Hope this solution is what you are looking for.
Seeking for Perl wisdom...on the process of learning...not there...yet!
| [reply] [d/l] [select] |
|
Re: Text Box control in Excel - how to reference in Perl
by poj (Abbot) on Sep 10, 2014 at 07:20 UTC | |
poj | [reply] [d/l] |