| View previous topic :: View next topic |
| Author |
Message |
akhil999in General User


Joined: 14 Feb 2007 Posts: 17 Location: India, New Delhi (was Calcutta)
|
Posted: Thu Dec 18, 2008 2:49 am Post subject: Macro to select entire row of table in ooWriter |
|
|
Need to write Macro Code in OOo Basic to select entire row of a table in ooWriter
I want to select entire row, i.e., all cells of current row of a table in ooWriter from a Macro.
After selecting it I intend to merge all the cells and do certain other operations.
Different rows might have different number of cells, so MoveRight will not match.
The Macro Recorder does not record movements at all, so the merging takes place
within one cell only.
What is the code for selecting entire row.
Please reply soon.
_________________ a m |
|
| Back to top |
|
 |
vitcaro OOo Advocate


Joined: 20 Feb 2007 Posts: 256 Location: Italy
|
Posted: Thu Dec 18, 2008 6:20 am Post subject: |
|
|
Here is an example:
| Code: |
Set TextTables = oDoc.getTextTables
Set TextTable = TextTables.getByName("Table2")
Set oRows = TextTable.getRows
'get the third row (row 2)
Set oRow = oRows.getByIndex(2)
'find the number of cells in the third row (row 2) (each row can have a different number of cells)
ColumnsCount = UBound(oRow.TableColumnSeparators) + 2
'create text cursor of first cell in the third row
Set TableCursor = TextTable.createCursorByCellName("A3")
'select all the cells of the third row (each row can have a different number of cells)
TableCursor.goRight ColumnsCount - 1, True
'merge all the cells of the third row
TableCursor.mergeRange
|
|
|
| Back to top |
|
 |
WarpedOne Newbie

Joined: 24 Feb 2009 Posts: 4
|
Posted: Thu Feb 26, 2009 8:02 am Post subject: |
|
|
If you need to select it in a way so you could copy it to clipboard you 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 |
|
 |
|
|
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
|