Closing PrintPreview mode in a macro

Keyboard macros or custom scripts

Closing PrintPreview mode in a macro

Postby trevorh7000 » Sat Mar 29, 2008 12:25 pm

Hi

I have a macro that opens all the spreadhseets in a directory and copies information from them and then closes them. It works great up till the point when I get to open a spreadheet that has been save in the state of a PrintPreview. Then the macro crashes. I figured the easiest way arround this would be open the spreadhseet and then close print preview but I am strugling. I used the macro recorder to see what the code should look like and got this.

dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:ClosePreview", "", 0, Array())

If I put a spreadsheet in PrintPreview mode and run this macro it works perfectly. Then I needed to convert it to work with my main macro and this is the code that I have come up with (hobbled together from other coded that woks in my macro!)

oSrcDoc = StarDesktop.loadComponentFromUrl(s,"_blank",0,Array()) - where s is the name of the file to open
dim documentx as object
dim dispatcherx as object
dispatcherx = createUnoService("com.sun.star.frame.DispatchHelper")
documentx = oSrcdoc.getCurrentController().getFrame()
dispatcherx.executeDispatch(documentx, ".uno:ClosePreview", "", 0, Array())

This has no effect on the document and PrintPreview mode is not closed and the program crashes.

I "copied" this syntax from the following lines which work!
oTargetframe = oTargetDoc.getCurrentController().getFrame()
oDispatcher.executeDispatch(oTargetframe, ".uno:InsertContents", "", 0, args4())

in that case the dispatcher properly pastes the clipboard contents into my target doc

So I do not understand why the dispatcher will not operate on the oSrcdoc and close the PrintPreview

Of course my understanding of all of this is not complete and I have just kludged it together from other examples - but to me it seems as if it should work.

What have I perhaps misunderstood and implemented incorrectly

Thanks

Trev
trevorh7000
 
Posts: 2
Joined: Sat Mar 29, 2008 11:50 am

Re: Closing PrintPreview mode in a macro

Postby B Marcelly » Sun Mar 30, 2008 10:13 am

Hi
trevorh7000 wrote:I have a macro that opens all the spreadhseets in a directory and copies information from them and then closes them. It works great up till the point when I get to open a spreadheet that has been save in the state of a PrintPreview. Then the macro crashes.

I did not know that Calc remembers the Preview state. This is not the case for Writer. It could be a Calc bug (or unvolontary feature).

Your macro crashes probably because you are using dispatcher instructions after you have loaded the document. If you use the API it will probably not crash (and may work faster). But that's another story.

Your code works for me (tested on Win XP and OOo 2.4.0 with a Calc doc saved in preview, and loaded from another document).
The problem is probably elsewhere in your code. It could be that you need to wait after the ClosePreview dispatch. Add one second delay before continuing:
Code: Select all   Expand viewCollapse view
wait 1000


______
Bernard
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Closing PrintPreview mode in a macro

Postby trevorh7000 » Wed Apr 02, 2008 4:50 pm

B Marcelly wrote:Hi
trevorh7000 wrote:I have a macro that opens all the spreadhseets in a directory and copies information from them and then closes them. It works great up till the point when I get to open a spreadheet that has been save in the state of a PrintPreview. Then the macro crashes.

I did not know that Calc remembers the Preview state. This is not the case for Writer. It could be a Calc bug (or unvolontary feature).

Your macro crashes probably because you are using dispatcher instructions after you have loaded the document. If you use the API it will probably not crash (and may work faster). But that's another story.

Your code works for me (tested on Win XP and OOo 2.4.0 with a Calc doc saved in preview, and loaded from another document).
The problem is probably elsewhere in your code. It could be that you need to wait after the ClosePreview dispatch. Add one second delay before continuing:
Code: Select all   Expand viewCollapse view
wait 1000



Thanks for testing this - it is very strange that it does not work for me. I would not know how to use the APII just hacked this code together from examples on the net. I am also using linux (ubuntu 7.10) with OOo2.3.0. I have just downloaded 2.4 for win and linux so will try the code in both and see if that makes a difference

I will post back with the results when I have had a chance to test it out

Trev
trevorh7000
 
Posts: 2
Joined: Sat Mar 29, 2008 11:50 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests