Hello Gurus,
I am begginer in perl. I would like to ask several questions, some related to perl and its syntax but most will be regarding to WIN32 OLE. My main goal is to develop script that will check word document structure (return some information) and make some changes in this document (if it is possible). I am not shure if all that can be done throught perl and OLE. First I am sorry for posting things regarding microsoft OLE but mostly things that I have found was from this site, I also tried MSDN but seems very unclear and useless to me. Latest experimienting with OLE drives me crazy so I hope somebody could help.
1st
===
How to properly start win32 OLE ? I found somewhere this approach:
Seems clear, just few questions to enshure that I understand:
1. Can i replace or with || both stands for logical or ?
2. What is really going on in this code:
The perl tries to capture some of running instances of word application, if fails then starts it own instance and if this fails the error is printed ? What would happend if it captures some existing instance, and how to create this instance, it is just started word process ?
3. I read in OLE documentation that second argument is destructor (but seems that is not mandatory), what is really its purpose ? i know it is opposite of constructor but, there needs to be some method created with name 'Quit' or it is done automatically or what is going on ?
4. What does those "::" and "->" in code above stands for ? Is it some accessing of methods in some package or class or whatever ?
5. 'use warnings;' is the same as perl -w ?
2nd
===
Some codes that I've found on internet regarding OLE cointinues with following:
but then also found some weird structures, such as:
First approach seems pretty clear, accessing method Open which is part of Document (class, package or whatever) but what does other do ?
What does mean {FileName => 'C:\\Perl\\home\\001f.doc', ReadOnly =>1} in fcunction arguments, why curly braces ?
What is the difference between '=>' and '->' ? Is closing properties (or what is correct name) in '{}' necessary ?
I have found that VBA has nearly simillar syntax 'ComputeStatistics(Statistic:=wdStatisticWords)' I am assuming this thing relates each other because in fact with OLE I am using microsoft technologies from perl. Also found solution which works with same functions/parameters as VBA (but without this strange assigment) here it is: Comment on
4th
===
As I mentioned it seems that perl, VBA and PowerShell codes that I've found have several in common (I am not exper neither of those languages but they are acessing simillar variables). Following page describes how to obtain number of words and number of pages from document. As one of user suggested it can be obtained with '$selection->Words->{Count};' and '$selection->pagenumbers->{Count};' construction. However if I search word 'selection' in Object Browser of M$ Visual basic (from word document hit alt+F11 and F2) I found following:
As you can see both contains also variables (or properties or what is the correct name, please correct) for 'Characters' and 'Words' but seems that both 'Characters' and 'Words' are member of 'Word.Selection' how should I understand that? Also I tried to search for 'pagenumbers' as it was mentioned in above link but did not find anything except several 'wdPageNumberStyle' and 'PageNumbers' but not 'pagenumbers' (lowercase). Also I did not find in Object Browser that 'Word.Selection.Words' or 'Word.Selection.Characters' have 'Count' method (or property what is correct name) where this method (property) came from ? What does word 'as' means in above output it is some data type ?
Here I am posting mentioned code which I slightly altered
but this code did not works perfectly. It always returns word count 1 no matter how many word are in document. Those investigations points me to another probably most important question, how are all those OLE objects organized ? The object browser is unclear to me, I also downloaded OLE/COM Object Viewer but bad luck also. I know this is not standard question to perl but I dont know where to ask. One idea which commes to mind is to list somehow all methods (properities variables packages) which are included in OLE throught perl, and then just try several of them according name, is this possible ?
5th
===
Is possible to process word document character by character ? Or even better is possible to query data from word like if it is SQL? Simply say select * from document where Font=Italic ?
I think that reading by words I have done here ()there are some little mistakes:
Works but throws some error at the end and did not proceed headers and footers
6th
===
I searched found following in Object Browser:
Const wdNumberOfPagesInDocument = 4
Member of Word.WdInformation
Const wdStatisticPages = 2
Member of Word.WdStatistic
What does mean thoe numbers ? I am shure they do not coresponds with actual number of word document pages (I was playing with code from which works Comment on)
7th
===
Finally last question, I read somewhere that full path is necessary in OLE to open word document. I would like to pass document to procesing as an argumen to script but without needing specify full path (whole path should be appended to it after it will be passed to script) found somewhere that 'abs_path($0)' is using to doing someting similar but I had no luck. Also on Windows the slashes must be escaped and so on.
I am sorry for longer post but I am stuck at points that I've described, hope somebody knows answer. Thanks a lot for any idea
Hi gurus
I am trying to understand some advanced (for me) perl constructions (syntax) following this tutorial I am trying to parse html:
Using Mojo::DOM | Joel Berger
say "div days:";
say $_->text for $dom->find('div.days')->each;
say "\nspan hours:";
say $_->text for... (1 Reply)
Hi gurus, i am trying to write simple perl script using win32 ole which will iterate over all M$ word paragraphs (any text that ends with a hard return) and print only those paragraphs that matches the specified condition. The problem is that I need to access font size property. It seems to me that... (0 Replies)
Hi all,
Is win32::OLE module is applicable in linux system???
from my understanding it is not possible..because we have to use some tools for that..for more info refer this website
http://oclug.on.ca/archives/oclug/2001-July/008100.html (1 Reply)
I am trying to insert a picture into a worksheet in Excel using Perl the following is the code
use Win32::OLE;
use Win32::OLE::Const "Microsoft Excel";
use Win32::OLE qw(in with);
# Initiate Excel application
$Excel = Win32::OLE->new('Excel.Application', 'Quit');
$Excel->{Visible} =1;
#... (1 Reply)
Hey guys,
I'm trying to go through my emails in Outlook until I find an email with a certain subject line.
I am able to send emails with no problem, but reading emails and their properties (From, Subject, etc.) is my main problem.
Basically, I don't know where to start and using search engines... (2 Replies)
Hello All,
I have executed one script where i am getting this error,what may be the reason.....
please help me out.
OLE exception from Microsoft Excel
Win32::OLE(0.1403) error 0x800a03ec
in METHOD/PROPERTYGET "open" (1 Reply)
Hi,
I am trying automate couting number of spell and typo errors in MS Word document using perl script.
In perl script, i am using Win32::OLE module of perl to read MS word document.
Can anybody tell me are there any modules available in perl which can be imported into my script to... (0 Replies)
I am using Win32::OLE to write a perl script which opens an excel file. That excel file is password protected and everytime i run that script dialog box pops up and I have to click on Read-Only then my script executes. Is there any way I can specify the readonly attribute in my code so i dont have... (0 Replies)
Hi friends,
I am using win32::ieautomation to automate portal
Please help me with below line of code:
my $target_cell = $table_object->tableCells(2, 5);
what is $table_object in above line
I am using $browser->getTable('id:', "table_id")->tableCells(2,5);
The error I get is can't... (0 Replies)