Page 1 of 1

[Solved] Calc Macro FreezeAtPosition is relative to location

Posted: Tue Oct 07, 2014 11:01 am
by miryamb
Hi,

I'm trying to write a very very basic Macro. I want it to Freeze the first line (to serve as headers).
When I used the dispatcher created automatically from the "record macro" - "dispatcher.executeDispatch(document, ".uno:FreezePanes", "", 0, Array())"
I got a popup asking if I want to set the first line as Headers.
in order to Avoid this popup I use:
"Doc.currentController.freezeAtPosition(0,1)".

My problem here is that it freezes the window relative to the active cell - i.e. If I'm standing on cell G16 when calling the Macro, it freezes the window at line 5, column F.

How can I make it work on the first line regardless of my current active cell? (I don't mind changing the active cell to A1, but for some reason no function I tried worked..)

Thanks a lot!
Miri

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 11:09 am
by RoryOF
The freeze is always to the cells above and to the left of the current cursor location, so you may need to move cursor to B1 to freeze A.

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 11:19 am
by miryamb
I figured as much :)

But I didn't manage to move the cursor to A1.

Tried:
Doc.CurrentController.GoToCell("A1")
and
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$A$1"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

Nothing worked..

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 11:21 am
by Villeroy
Don't select A1 when you want to split above A2.

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 11:23 am
by miryamb
it kept splitting at my original location

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 11:25 am
by Villeroy

Code: Select all

Sub freeze_row_one()
oView = ThisComponent.getCurrentController()
oView.freezeAtPosition(0,1)
End Sub

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 11:34 am
by miryamb
Tried this just now - didn't work ..
However I found out something interesting.

If my view includes the First line - it works fine (i.e. my location is C5)
If my view doesn't include the first line - it doesn't work (i.e. my location is Z50)

I need to change the view somehow.

Any ideas?

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 3:37 pm
by B Marcelly

Code: Select all

Dim ThisController As Object, currPos As Object

ThisController = ThisComponent.CurrentController
currPos = ThisController.Selection
ThisController.FirstVisibleRow = 0
ThisController.freezeAtPosition(0,1)
ThisController.select(currPos)

Re: In Calc Macro FreezeAtPosition is relative to my locatio

Posted: Tue Oct 07, 2014 4:38 pm
by miryamb
Worked like a charm !!

Thank you very much :) I'll change the post name to solved

BTW - is there a place I can find all the fields of the controller (.Selection / .Select / .FirstVisibleRow)?