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

Writer - How to copy a table row including its content?

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


Joined: 24 Feb 2009
Posts: 4

PostPosted: Tue Feb 24, 2009 5:54 am    Post subject: Writer - How to copy a table row including its content? Reply with quote

I have a writer document with a table with two rows - a header row and a "template" row. This "template" row includes keywords that I need to replace with some values. I don't know infront how many rows there would be, so my strategy is this:
1. select and copy template row to clipboard
2. replace values in selected template row
3. paste template row from clipboard and append it to the table
4. repeat 1 - 3 as needed
5. remove last (template) row

Trouble is I just cannot find out how to
- select a single table row in a way that I could then copy it to clipboard (via dispatching uno:Copy)
- paste this row from clipboard in a way that it will "append" to existing table

If anyone could shed some light over this I'd be very thankful. I need to code it in PowerBuilder via OLE but some VB or Java code samples would be fine.
If you have an alternative solution to using clipboard that would be fine too.

Anyone?

Edit: Let me add that even if you don't have a solution to all the steps any hint would be equally welcome Very Happy


Last edited by WarpedOne on Thu Feb 26, 2009 8:05 am; edited 1 time in total
Back to top
View user's profile Send private message
WarpedOne
Newbie
Newbie


Joined: 24 Feb 2009
Posts: 4

PostPosted: Thu Feb 26, 2009 8:05 am    Post subject: Reply with quote

I figured it out! For uno:copy to work, we must use view cursor. Here is the code that selects last row in a table and duplicates it via clipboard (including all formating).

Code:

OLEObject oVC, objTable, oDispatcher
Any l_objPropertyValues[]
Any l_Separators[]

l_objPropertyValues[1] = i_objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oDispatcher = i_objServiceManager.createInstance("com.sun.star.frame.DispatchHelper")

// we need ViewCursor to visualy select content
oVC = i_ole_doc.getCurrentController.getViewCursor()

// get first table in a document
objTable = i_ole_doc.getTextTables().getByIndex(1)

// get cell separators from last row
l_Separators = objTable.getRows().getByIndex(objTable.getRows().getCount() - 1).TableColumnSeparators   

// figure out the cell count
ll_count = Upperbound(l_Separators) + 1

// step into first cell in last row - via VIEW CURSOR
oVC.gotoRange(objTable.getCellByName("A" + String(objTable.getRows().getCount())).createTextCursor(),FALSE)   
i_ole_doc.CurrentController.Frame.getContainerWindow().Setfocus()

// select all cells in this last row
oVC.goRight(ll_count, true)

// copy to clipboard
oDispatcher.executeDispatch(i_ole_doc.CurrentController.Frame, ".uno:Copy",  "", 0, l_objPropertyValues)

// add one row to the table
objTable.getRows().insertByIndex(objTable.getRows().getCount(), 1)

// step into first cell in this new last row
oVC.gotoRange(objTable.getCellByName("A" + String(objTable.getRows().getCount())).createTextCursor(),FALSE)
i_ole_doc.CurrentController.Frame.getContainerWindow().Setfocus()

// select all cells in last row
oVC.goRight(ll_count, true)

// paste from clipboard
oDispatcher.executeDispatch(i_ole_doc.CurrentController.Frame, ".uno:Paste",  "", 0, l_objPropertyValues)
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