| View previous topic :: View next topic |
| Author |
Message |
backupval Newbie

Joined: 08 Jun 2004 Posts: 2
|
Posted: Wed Jun 09, 2004 5:54 am Post subject: Doubt: what can I do to enumerate a texttable column? |
|
|
Hello
My name´s Valério Farias, I'm brazilian
I need your help in write macro for texttables.
I want to know how to get the current select column, from current texttable, from current document.
And after to enumerate the select column.
I use the openoffice.org 1.1.0 brazilian version.
I obtained only to enumerate the fist column from first texttable, how you can see in next souce code:
Option Explicit
Dim oDocument as Object
Dim sDocumentTitle as String
Sub Main()
Dim oTable as Object
Dim oRows as Object
Dim oDocuText as Object
Dim oAutoTextCursor as Object
Dim oAutoTextContainer as Object
Dim oAutogroup as Object
Dim oAutoText as Object
Dim oCharStyles as Object
Dim oContentStyle as Object
Dim oHeaderStyle as Object
Dim oGroupTitleStyle as Object
Dim n, m, iAutoCount, tmp as Integer
BasicLibraries.LoadLibrary("Tools")
sDocumentTitle = "Installed AutoTexts"
oTable = odocument.texttables(0) ' table 1
'oTable = oDocument.currentSelection .............If I run with this line return a error
If Not IsNull(oTable) Then
oDocuText = oDocument.Text
' The Characterstyle for the Header that describes the Title of Autotextgroups
oGroupTitleStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
oGroupTitleStyle.CharHeight = 14
' The Characterstyle for the Header that describes the Title of Autotextgroups
oHeaderStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle")
' oCharStyles.InsertbyName("AutoTextHeading", oHeaderStyle)
oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
oAutoTextCursor = oDocuText.CreateTextCursor()
For n = 0 To otable.rows.count - 1
InsertStringToCell(n+1, oTable.GetCellbyPosition(0, n), "TableContent")
Next n
End If
End Sub
Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
Dim oCellCursor as Object
oCellCursor = oCell.CreateTextCursor()
'oCellCursor.CharStyleName = sCellStyle
oCell.Text.insertString(oCellCursor,sCellString,False)
oDocument.CurrentController.Select(oCellCursor)
End Sub |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3623 Location: Columbus, Ohio, USA
|
Posted: Wed Jun 09, 2004 7:30 pm Post subject: |
|
|
Hello Valério Farias, I see that you made it here. I caught up on some of my work until my copy editor sends me more so I figured that I would tackle some of your questions. In your code, you ahve the following:
| Code: | oTable = odocument.texttables(0) ' table 1
'oTable = oDocument.currentSelection .............If I run with this line return a error |
The first line is fine, it obtains the first text table. The second line of code, I usually use the getCurrentSelection() method, but I do not know why this fails for you. Hmmmm. Then again, you do not want the current selection anyway, you just do not know it yet
Your first question:
| Quote: |
I want to know how to get the current select column, from current texttable, from current document. |
I finally figured out what you are asking here. You want to know which column contains the cursor. The following code obtains the current table AND the current cell. I did not test to see if more than one cell is selected. The macro may fail if this is true, I did not check this.
| Code: | Sub TableStuff
Dim oVCurs 'The view cursor
Dim oCurCell 'Current Cell
Dim oTable 'The contained table
oVCurs = ThisComponent.getCurrentController().getViewCursor()
REM Is the cursor in a table?
If IsEmpty(oVCurs.TextTable) Then
Print "The cursor is NOT in a table"
Exit Sub
End If
REM I did not test this if multiple cells are selected.
REM This is ONLY to get you started
oTable = oVCurs.TextTable
oCurCell = oVCurs.Cell
Print "The cursor is in cell " & oCurCell.CellName
End Sub |
You want to enumerate the cells in the current column. I do not have time to try this at the moment, but I have two suggestions.
1 You know the cell name, and you can inspect this to determine the column. finally, you can use methods such as the following to extract cells:
OBJECT getCellByName ( STRING )
OBJECT getCellByPosition ( LONG, LONG )
ARRAY getCellNames ( void )
OBJECT getCellRangeByName ( STRING )
OBJECT getCellRangeByPosition ( LONG, LONG, LONG, LONG )
ARRAY getColumnDescriptions ( void )
OBJECT getColumns ( void )
The view cursor supports the following methods:
BOOL goDown ( INTEGER, BOOL )
BOOL goUp ( INTEGER, BOOL )
Be warned, however, you can probably move the cursor out of the table. Also, I am assuming that you have a simple table rather than a complex table. You might also be able to simply obtain the column in question directly from the table, but I do not have time to check this either. _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
Danad OOo Advocate

Joined: 22 Feb 2004 Posts: 293 Location: Brasil
|
|
| Back to top |
|
 |
Guest
|
Posted: Tue Jun 15, 2004 12:26 pm Post subject: Thanks |
|
|
Thak you so much for you help
I finish the macro.
Now I have to distribute it in about 200 Computers here in the University.
Macro code:
| Code: | Sub Main()
Dim n
Dim oVCurs 'The view cursor
Dim oCurCell 'Current Cell
Dim oTable 'The contained table
Dim ocol
oVCurs = ThisComponent.getCurrentController().getViewCursor()
REM Is the cursor in a table?
If IsEmpty(oVCurs.TextTable) Then
MsgBox "The cursor is NOT in a table"
Exit Sub
End If
oTable = oVCurs.TextTable
oCurCell = oVCurs.Cell
ocol = Asc(Left(trim(oCurCell.CellName),1))-64 ' return the column index
For n = 0 To otable.rows.count - 1
oTable.getCellByPosition(ocol-1,n).setstring("")
oTable.getCellByPosition(ocol-1,n).setstring(n+1)
Next n
End Sub |
|
|
| Back to top |
|
 |
backupval Newbie

Joined: 08 Jun 2004 Posts: 2
|
Posted: Tue Jun 15, 2004 12:31 pm Post subject: Thanks |
|
|
Thank you so much for you help
I finish the macro.
Now I have to distribute it in about 200 Computers here in the University.
Macro code:
| Code: | Sub Main()
Dim n
Dim oVCurs 'The view cursor
Dim oCurCell 'Current Cell
Dim oTable 'The contained table
Dim ocol
oVCurs = ThisComponent.getCurrentController().getViewCursor()
REM Is the cursor in a table?
If IsEmpty(oVCurs.TextTable) Then
MsgBox "The cursor is NOT in a table"
Exit Sub
End If
oTable = oVCurs.TextTable
oCurCell = oVCurs.Cell
ocol = Asc(Left(trim(oCurCell.CellName),1))-64 ' return the column index
For n = 0 To otable.rows.count - 1
oTable.getCellByPosition(ocol-1,n).setstring("")
oTable.getCellByPosition(ocol-1,n).setstring(n+1)
Next n
End Sub |
|
|
| Back to top |
|
 |
davefloripa General User

Joined: 22 Sep 2004 Posts: 8
|
Posted: Thu Sep 23, 2004 10:33 am Post subject: Re: Doubt: what can I do to enumerate a texttable column? |
|
|
ola,
eu li que vc é brasileiro...
e eu tbm sou...
vc entende bem de open office..APi...etc???
poderias me dar uma ajuda...
valeu,
abraço |
|
| 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
|