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 use a method from XCellCursor?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Jmadsen
Power User
Power User


Joined: 13 Feb 2004
Posts: 53
Location: Denmark

PostPosted: Mon Dec 13, 2004 2:02 am    Post subject: How to use a method from XCellCursor? Reply with quote

I want to use the method "gotoNext" before saving my spreadsheet - how do I access this method?
Edit: this is the link from the API:
http://api.openoffice.org/docs/common/ref/com/sun/star/table/XCellCursor.html

I have a hard time understanding the API, so if anyone could explain this to me or point me in the direction of an explanation, it would be very helpful.

Thanks!

/jmadsen
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 8976
Location: Lexinton, Kentucky, USA

PostPosted: Mon Dec 13, 2004 4:59 am    Post subject: Reply with quote

Have you looked at DannyB's Calc Examples in the Code Snippets section of the forum?
Back to top
View user's profile Send private message
Jmadsen
Power User
Power User


Joined: 13 Feb 2004
Posts: 53
Location: Denmark

PostPosted: Mon Dec 13, 2004 5:20 am    Post subject: Reply with quote

JohnV wrote:
Have you looked at DannyB's Calc Examples in the Code Snippets section of the forum?


Yes I have looked at some of them, but couldn't find anything about CellCursor when I searched the forum.

/jmadsen
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Mon Dec 13, 2004 9:27 am    Post subject: Reply with quote

Which Language ?
From Bernard Marcelly French Document :
Code:

Dim MonCurseurCellule As Object, UneCellule As Object

MonCurseurCellule = MaFeuille.createCursor
MonCurseurCellule.gotoStart
MonCurseurCellule.gotoNext
UneCellule = MonCurseurCellule.getCellByPosition(0,0)
UneCellule.String = "Bonjour"

MonCurseurCellule.gotoEnd
rem descendre d’une ligne
MonCurseurCellule.gotoOffset(0, 1)
MonCurseurCellule.getCellByPosition(0,0).String = "Bonsoir"


Bernard says in his document he is not sure this service works properly.
Sorry i don't know more.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
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: Mon Dec 13, 2004 9:41 am    Post subject: Reply with quote

From your spreadsheet, that is, an individual sheet, you have the XSpreadshset interface.

You would call the createCursor() or createCursorByRange() methods.

Note that both methods return an XSheetCellCursor. Therefore, you can call all methods of XSheetCellCursor, and its inherited interfaces. But if you look carefully at the documentation of both methods, you'll see that both methods say See Also: SheetCellCursor. Both methods not only return the XSheetCellCursor interface, but it is actually a SheetCellCursor service, which this interface is a part of.

You can see that the SheetCellCursor includes the service CellCursor. You can also see that CellCursor has the interface XCellCursor.

Therefore, on a spreadsheet, just call either of the two methods createCursor() or createCursorByRanage() and you then have an XCellCursor which you can use to call its methods.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Jmadsen
Power User
Power User


Joined: 13 Feb 2004
Posts: 53
Location: Denmark

PostPosted: Tue Dec 14, 2004 3:56 am    Post subject: Reply with quote

DannyB wrote:
From your spreadsheet, that is, an individual sheet, you have the XSpreadshset interface.

You would call the createCursor() or createCursorByRange() methods.

Note that both methods return an XSheetCellCursor. Therefore, you can call all methods of XSheetCellCursor, and its inherited interfaces. But if you look carefully at the documentation of both methods, you'll see that both methods say See Also: SheetCellCursor. Both methods not only return the XSheetCellCursor interface, but it is actually a SheetCellCursor service, which this interface is a part of.

You can see that the SheetCellCursor includes the service CellCursor. You can also see that CellCursor has the interface XCellCursor.

Therefore, on a spreadsheet, just call either of the two methods createCursor() or createCursorByRanage() and you then have an XCellCursor which you can use to call its methods.


The problem for me is, that when I look at the page for XCellCursor:
http://api.openoffice.org/docs/common/ref/com/sun/star/table/XCellCursor.html
It doesn't say that I should use the CreateCursor() method to create one. I don't think the API is very logical and I have a problem finding out which methods go with which objects, and I would like to know if there actually IS some kind of logic to this and if anyone can explain that logic to me?!

/jmadsen - yep, I might just be stupid!
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


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

PostPosted: Tue Dec 14, 2004 10:05 am    Post subject: Reply with quote

You have a good point about the XCellCursor interface not describing how to get such an interface.

Even though the description I gave you was in the "forward" direction, I was able to actually work backwards from XCellCursor to see how it was created.

Starting from the XCellCursor page, I was able to click the Use link at the top of the page.

Then I could see "Services which support this interface", which includes CellCursor.

So how to get a CellCursor?

Well, clicking the Use link at the top of the CellCursor page, shows me that a CellCursor is actually part of a SheetCellCursor.

At this point, I was well on my way towards understanding XCellCursor.

The SheetCellCursor page has a Use link at the top of its page. From there, I found linked references in the Developer's Guide, which helped.


There really is a certian logic to the API reference.

An interface, such as XIndexAccess, is implemented by many possible collections. Furthermore, other than my own custom container components, I don't know of any service that you can actually create to have an XIndexAccess interface.

But many things implement XIndexAccess. For instance, the collection of draw pages, or impress slides, or Calc spreadsheets. Any time you call getCount() or getByIndex() you are using XIndexAccess.

oDoc = ....drawing document....
oDrawPage = oDoc.getDrawPages().getByIndex( 0 )

oDoc = .....spreadsheet document....
oSheet = oDoc.getSheets().getByIndex( 0 )

And many, many other collections use XIndexAccess. Even new components might use it. For instance, if I implement a new service in uno, and add it to the office, and my new service implements XIndexAccess; then how is the documentation supposed to know about my new service and how is it supposed to tell you how to obtain and use my new service?

Similarly, my new custom component could implement the XCellCursor interface. How is the documentation supposed to know about that?

The only answer is that you work forwards from the services to the interfaces. Not backwards from the interfaces back to their services.

If you start from the service.....

com.sun.star.sheet.Spreadsheet

you would discover that createCursor, and createCursorByRange, both return a service, which includes XCellCursor (plus other interfaces!).

If you start from the documentation of....

name.DannyBrewer.misc.MyNewCustomService

you would discover that someFooBarMethod would return some service which includes the XCellCursor interface (plut other interfaces).

I hope that makes sense.

Still you make a good point about there needing to be a "simplified" reference document for the casual OOo API programmer. I have thought about this many times. I am interested in producing a tool that would read the source IDL files and produce a more detailed cross reference document of the API than the current documentation that the SDK provides us with.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
morningnapalm
Newbie
Newbie


Joined: 18 Sep 2009
Posts: 1

PostPosted: Fri Sep 18, 2009 6:07 am    Post subject: Help xCellCursor Reply with quote

I am just starting to use OOBasic and am trying to understand how to use the api and just the basic programming methods. I am reasonably familiar with VBA in Excel as a starting point.

So following this post, it looks like I need to use the createCursor method to create one and then I can use the gotoEnd method once the cursor is created. I am struggling to find examples of how this actually looks.

How do I implement createCursor?
Once that is done, how do I then use the gotoEnd method of it?

I have this simple code I am using to test it. I am just trying to start with a cell selected and then go to the end of the range. Ultimately, I would like to select a cell below the range and then go "up" to find the last cell in the range that contains data.



Code:
Sub Testing

Dim oDoc as object
Dim oSheet as object
Dim oCell as object

oDoc = thisComponent
oSheet = oDoc.Sheets.getByName("Sub1")
oCell =  oSheet.getCellByPosition(3,0)
oCell.xCellRange.gotoEnd()


End Sub


I also recorded a macro to do the same thing and it looks like this. It uses a dispatcher, which I have not figured out yet, but seems like a lot of code to do a simple thing.

Code:
sub Trial
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "By"
args1(0).Value = 1
args1(1).Name = "Sel"
args1(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDownToEndOfData", "", 0, args1())


end sub
Back to top
View user's profile Send private message
fbcam
Newbie
Newbie


Joined: 28 Sep 2010
Posts: 1
Location: Kansas

PostPosted: Tue Sep 28, 2010 3:07 pm    Post subject: Reply with quote

Hello out there. Is anyone interested in answering? I would like to use Open Office more but I can't because I cannot figure out how to create a very simple macro. All I want to do is copy the contents of a table cell into the cell below and then move to the next cell.

After doing some reading in this thread, it seems like "com.sun.star.table.XCellCursor.gotoOffset(0,-1)" should do it but it doesn't. What else is needed?

I recorded a macro (That does not recreate what was done while recording it btw.) and it contains lots of stuff including "Uno:GoUp". I tried searching for Uno in the OO Help and it could not find it. I tried searching for many of the recorded commands and could find none of them in OO Help.

Thanks for any help any of you want to provide.
_________________
Fred
Back to top
View user's profile Send private message
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