[Solved] Macro Set Page Format To Portrait

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

[Solved] Macro Set Page Format To Portrait

Post by misitu »

Hello.

My charts are wider than deep. I am saving as a spreadsheet and also exporting to PDF. The problem arises in that I cannot see how to set to PORTRAIT in a way that the PDF Export finds acceptable.

What is happening is that the PDF is produced in landscape, truncating the charts to "print" in parts on different pages.

In manual mode, setting the Format>Page> to Portrait, and tweaking the X's and Y's appropriately, I can print the two charts on their own pages with no overlap, truncation, etc.

I have this piece of code

Code: Select all

dim PrintOptions(0) as new com.sun.star.beans.PropertyValue
PrintOptions(0).Name = "PaperOrientation"
PrintOptions(0).Value = com.sun.star.view.PaperOrientation.LANDSCAPE	
but I am not clear how to link it to the worksheets.

There are two sheets, the data sheet where all the data is loaded, and the charts sheet where the charts are produced. The latter is sheet(0) and the other is sheet(1).

I have tried dropping these lines into several likely places but I always end up with the IOException message, pointing to the "Save as .ods" line:

Code: Select all

ThisComponent.storeAsURL(storeAsUrl, args_ODS())
All assistance welcome and gratefully received.

Thanks
David
Last edited by misitu on Thu Jun 23, 2016 4:23 pm, edited 1 time in total.
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro Set Page Format To Portrait

Post by Zizi64 »

The print orientation and the page (sheet) orientation are not same properties.
You need use a landscape sheet style (page style) instead of the portrait one.

You can apply a page style by a macro or manually.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Macro Set Page Format To Portrait

Post by misitu »

Thanks, Zizi.

From the brevity of your reply I figured the question had already been answered.

This was all that's needed, apart from this prologue

In sum, following my

Code: Select all

	oSheets.insertNewByName("Chart", 0)
, where the specific sheet is defined, I add from the above

Code: Select all

  oStyleFamilies = ThisComponent.StyleFamilies 'ThisComponent refers to the document that called the macro
  oPageStyles = oStyleFamilies.getByName("PageStyles")  'oPageStyles is a collection of all of the Page styles
  DefPage = oPageStyles.getByName("Default")
' 
DefPage.IsLandscape = True
DefPage.Width = 29700  
DefPage.Height = 21000
and BINGO, I now have an acceptable landscape layout. :D

For anyone following this up, I would comment that you do need both the IsLandscape (which changes the radio button on the Format>Page> dialog, and also the Width and Height since, as Bernard said earlier,
The API is not very smart...
, it is indeed I would say the result of a bit of faulty oversight somewhere in the API translator (probably a bit of lazy reuse of a variable)... never mind, it all works now thanks to yourself and Bernard in the earlier post.

It is not difficult to work out that you guys KNOW when a question has already been answered :super:

Best regards
David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
Post Reply