Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

cause a delay in script

by momukhtar (Initiate)
on Jul 26, 2007 at 21:09 UTC ( [id://629002]=perlquestion: print w/replies, xml ) Need Help??

momukhtar has asked for the wisdom of the Perl Monks concerning the following question:

I am using the Workbooks->Open method in read only mode and then converts all the chart objects in the excel file into png images. The problem is that it takes a while for excel to produce charts correctly and the script executes as soon as the file is opened, because of this the images are not the same as the actual charts and the curves are not proper. What is the way to insert a delay in the script so that the charts are produced correctly and then they are exported into images. Here is my code:
my $Book = $Excel->Workbooks->Open( $filename, 0, 1 ); foreach my $ChartObj (in $Book->Charts) { my $chartName = $ChartObj->Name; my $savename = $filepath."\\$chartName.$filter"; $ChartObj->Export({ FileName => $savename, FilterName => $filter, Interactive => 0}); } $Book->Close;
I want to insert a delay between open method and for loop.

Replies are listed 'Best First'.
Re: cause a delay in script
by FunkyMonk (Chancellor) on Jul 26, 2007 at 21:18 UTC
    The usual way is to use sleep, but that uses an integer for the number of seconds. If you want less of a delay, use Time::HiRes 'sleep'. That gives fractional second sleeps.
      I slept the script even for 60 seconds but that problem is still there. Any other ideas that why the png of those chart objects is not the same in shape as those chart objects in excel file.

        Do you get the same (bogus) results when you do the same thing by hand within Excel? Do you get the same (bogus) results if you record a macro in Excel to do the same thing?

        Generally recording an Excel macro to perform a task, then modeling your Perl script on the macro produces best results.


        DWIM is Perl's answer to Gödel

        I have seen this type of annoying behaviour in both Excel and Word which leads me to think that it has something to do with OLE itself. I have several programs where I had to put in a sleep 3 here and a sleep 5 there, which sucks of course. If you enable the visible property of the application thing gets even worse.

        From what I've gathered perl's interface to OLE is "single-threaded", aka methods shouldn't return until done, but that is not the case obviously.

        There are some properties in Word/Excel which enables "background" processing, mainly printing and spell checking, that you could try to disable, this is just a hunch on my part that may improve your situation or most probably not.

        I have tried extensively to find some property that would indicate if the OLE engine is in idle state which would be pollable, mainly as a workaround, but have come up with nothing so far.

        I am interested to hear what progress you make, collecting evidence to crack this issue I guess.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://629002]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found