[Solved] Macro to set row height to 0.

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
MATT.B
Posts: 165
Joined: Tue Nov 18, 2014 2:16 am

[Solved] Macro to set row height to 0.

Post by MATT.B »

so im trying to set the row height to 0 on my aoo calc document. and im having a bit of issue with this code.
i'm sure that getcellrangebyname is not the correct way to identify what row and i think it may be the cause for my issue. row 11 changes to .08 but rows 9 and rows 11 do not change at all but also dont produce an error.
row 9 and 10 must stay or i will have to rewright 6 pages of formulas and a bunch of macro code but because i added row 50 i need to shrink 2 rows to 0 and one to .08 to keep the pages printing correctly.

Code: Select all

oDoc = ThisComponent
oView = oDoc.getCurrentController()
oframe = oview.Frame
osheet = ThisComponent.getSheets().getByIndex(0)
	oB2 = oSheet.getCellrangeByName("A9")
	oRow = oB2.getRows()
	oRow.Height = 0.00 * 25.4 * 100
	oB2 = oSheet.getCellrangeByName("A10")
	oRow = oB2.getRows()
	oRow.Height = 0.00
	oB2 = oSheet.getCellrangeByName("A11")
	oRow = oB2.getRows()
	oRow.Height = 0.08 * 25.4 * 100
Last edited by MATT.B on Fri Dec 20, 2019 2:24 am, edited 1 time in total.
OpenOffice 4.1.1 ON WINDOWS 7 64
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: macro to set row height to 0.

Post by Lupp »

First of all: What do you expect

Code: Select all

...= 0.00 * 25.4 * 100
to return. Any number multiplied with 0 gives 0.

Then: What do we expect a row height set to 0 to bring about? In fact it should not change the property .Height, but set the property .IsVisible false. So does LibO, and so should AOO do according to "tradition". My AOO V4.1.5, on the other hand, is not handling it this way, but simply ignores the assignment. Therefore use instead:

Code: Select all

oB2.Rows.IsVisible = False
And:
I'm sure that getcellrangebyname is not the correct way to identify what row and i think it may be the cause for my issue.
No.

Code: Select all

oSheet.getCellRangeByName("A9").Rows
actually identifies correctly the row containing cell A9.

Generally I would dissuade from any attempt to adjust printing by complicated manipulations of row heights. You cannot even know if the next version also (?) will accept the "subliminal" settings you try . Use the page styles instead.

(By the way: English uses uppercase letters in some places.)
Last edited by Lupp on Fri Dec 20, 2019 1:53 am, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
FJCC
Moderator
Posts: 9273
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: macro to set row height to 0.

Post by FJCC »

Try using the IsVisble property of the rows to hide them.

Code: Select all

oSheets = ThisComponent.getSheets()
oSheet1 = oSheets.getByName("Sheet1")
oRows = oSheet1.getRows()
oRow = oRows.getByIndex(8)
oRow.IsVisible = FALSE
oRow = oRows.getByIndex(9)
oRow.IsVisible = FALSE
oRow = oRows.getByIndex(10)
oRow.Height = 0.08 * 25.4 * 100
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
MATT.B
Posts: 165
Joined: Tue Nov 18, 2014 2:16 am

Re: macro to set row height to 0.

Post by MATT.B »

Lupp wrote:First of all: What do you expect

Code: Select all

...= 0.00 * 25.4 * 100
to return. Any number multiplied with 0 gives 0.

its was actually a test to see if it mattered originally it was just 0 but was changed just in case it required that formatting to work
OpenOffice 4.1.1 ON WINDOWS 7 64
MATT.B
Posts: 165
Joined: Tue Nov 18, 2014 2:16 am

Re: macro to set row height to 0.

Post by MATT.B »

Lupp wrote: Generally I would dissuade from any attempt to adjust printing by complicated manipulations of row heights. You cannot even know if the next version also (?) will accept the "subliminal" settings you try . Use the page styles instead.
(By the way: English uses uppercase letters in some places.)

its more than just printing i also have about 20 pages of macros that operate around individual cells and formulas all over the sheet with 6 sheets and i really don't want to have to edit every line of code. its basically a mini program that operates inside AOO Calc that is used on 4 machines. its what we use for making repair estimates for our customers and we received feed back that our total price was hard to find so we moved it.the macro i'm working on modifies already saved files to meat the new format of the page it will most likely be used for about a week and then deleted from the code

but thank you for your help that worked nicely.
OpenOffice 4.1.1 ON WINDOWS 7 64
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Macro to set row height to 0.

Post by Lupp »

MATT.B wrote:I also have about 20 pages of macros that operate around individual cells and formulas all over the sheet with 6 sheets and I really don't want to have to edit every line of code. It's basically a mini program that operates inside AOO Calc that is used on 4 machines.
Just a guess(?): Bad design.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply