OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to set view based on Row (updated)

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Marinus
OOo Advocate
OOo Advocate


Joined: 07 Nov 2004
Posts: 261

PostPosted: Wed Dec 08, 2004 5:46 am    Post subject: How to set view based on Row (updated) Reply with quote

Hi,

is it possible to scroll through a Calc sheet with a macro?

I.e., get Row as integer and set the top of the view (what you see on your screen) to that Row.

Tx,

Marinus.


Last edited by Marinus on Fri Dec 10, 2004 10:03 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Dec 08, 2004 10:07 am    Post subject: Reply with quote

When you get the document's current controller, on a spreadsheet, this returns the SpreadsheetView service.

The SpreadsheetView service includes the SpreadsheetViewPane service.

The SpreadsheetViewPain service offers the XViewPane interface.

Therefore, on Basic, you can....
Code:
Sub Main
   oDoc = ThisComponent
   oDocCtrl = oDoc.getCurrentController()
   
   oDocCtrl.setFirstVisibleColumn( 13 )
   oDocCtrl.setFirstVisibleRow( 260 )
End Sub

_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Marinus
OOo Advocate
OOo Advocate


Joined: 07 Nov 2004
Posts: 261

PostPosted: Wed Dec 08, 2004 10:22 am    Post subject: Reply with quote

Danny,

thanks so much. It works great and I am learning so much of the classes in OO..

In a couple of days I'm going to post the logbook (that's what I'm making) to

www.flyinghours.com

so you can see what's going on if you like.

Marinus.
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Dec 08, 2004 12:20 pm    Post subject: Reply with quote

Glad to hear it.

In the above, find SpreadsheetViewPain, and replace with SpreadsheetViewPane.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Marinus
OOo Advocate
OOo Advocate


Joined: 07 Nov 2004
Posts: 261

PostPosted: Wed Dec 08, 2004 4:47 pm    Post subject: Reply with quote

Danny,

neither in the Programmers guide, the API guide nor in the ViewPane/SpreadsheetView settings can I find a reference to the cursor position.
All Get/SetCursor examples I can find here are for writer..

The problem is that with the setFirstVisibleRow below a Window - Freeze split and the cursor outside this range, the view is not reset.

Only when the cursor is below the Freeze line ....

A simple solution would be to set the cursor to one row below the split, but guess what.. don't know how to do that ..

Do you know (I'm sure you do) where I can find the cursor controls for Calc?

Thanks,

Marinus.
Back to top
View user's profile Send private message Visit poster's website
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Wed Dec 08, 2004 9:00 pm    Post subject: Reply with quote

This is because you can not find out where the cursor really is.... In fact, when you are editing a specific cell, you are actually in a special text input box of sorts so things become rather tricky if you wanted to use a "cursor" in a calc document.

I have an entire section on this in my free macro document. See the section titled ActiveSheet and ActiveCell. Thie refers you back to the section titled Selected text, what is it?, which goes into more detail on how to obtain the cell that contains the cursor, even if more than a single cell is selected...
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Marinus
OOo Advocate
OOo Advocate


Joined: 07 Nov 2004
Posts: 261

PostPosted: Fri Dec 10, 2004 11:17 am    Post subject: Reply with quote

Hi Danny and Andrew,

I have found out how to set the view AND cursor to the area below the pagesplit even
when the cursor is above the pagesplit at that time.

This probably was posted before but I just could not find it....Smile

The only problem is that until I click below the page split with the mouse, the tab- and cursorkeyscycle doesn't work (It cycles between the pusbuttons above the split and when this cycle is complete it comes back to below the split).

Is that solveable?


Code:
sub Main

   SetCursorTo( "MySheet", 1, 20 )
   SetViewTo ( 1, 20 )

end sub


sub SetCursorTo( nSheet as string, nColumn as long, nRow as long )

   oDoc = ThisComponent
   
   ' Avoid IndexOutOfBounds exception
   if nColumn < 1 then nColumn = 1
   if nColumn > 259 then nColumn = 259
   if nRow < 1 then nRow = 1
   if nRow > 32000 then nRow = 32000
   
   
   ' Detect invalid sheet name
   if not oDoc.getSheets.HasByName( nSheet ) then
      msgbox "Sheet " + nSheet + " does not exist!" + Chr(13) + Chr(13) +_
       "Cursor not set"
   else
      ' Set cursor
      Cell = oDoc.getSheets().getByName(nSheet).getCellByPosition(_
       nColumn - 1, nRow - 1)
      oDoc.CurrentController.Select(Cell)
   end if

end sub


sub SetViewTo( FirstColumn as integer, FirstRow as integer )

   oDoc = ThisComponent
   
   oDocCtrl = oDoc.getCurrentController()
   
   oDocCtrl.setFirstVisibleColumn( FirstColumn - 1 )
   oDocCtrl.setFirstVisibleRow( FirstRow - 1 )

end sub


Thanks for all the help.

Marinus.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group