WarpedOne Newbie

Joined: 24 Feb 2009 Posts: 4
|
Posted: Tue Feb 24, 2009 5:54 am Post subject: Writer - How to copy a table row including its content? |
|
|
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 
Last edited by WarpedOne on Thu Feb 26, 2009 8:05 am; edited 1 time in total |
|
WarpedOne Newbie

Joined: 24 Feb 2009 Posts: 4
|
Posted: Thu Feb 26, 2009 8:05 am Post subject: |
|
|
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) |
|
|