[Solved] Writer macro to select entire cell in text table

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jcdole
Posts: 4
Joined: Wed Mar 14, 2012 3:17 pm

[Solved] Writer macro to select entire cell in text table

Post by jcdole »

Hello.
I have make some macro using the recorder to change text colors in the current cell of a text table.
What is working (only 2 samples of what I use) :
1°) Changing the text from automatic character color with no highlighting (no fill) with no background color (no fill)
to white character color with no highlighting (no fill) and with grey 20% background color ( and the reverse ).
2°) Changing the text from automatic character color with no highlighting (no fill) with no background color (no fill)
to white character color with green 7 highlighting and with no background color (no fill) (and the reverse).

What I would like to add :
Changing the text from automatic character color with no highlighting (no fill) with no background color (no fill)
to white character color with green 7 highlighting and light magenta background color (and the reverse).

Using the recorder what I get is a text in white character color with green 7 highlighting and light magenta background color with two horizontal stripes on both sides of the text. As if the cell was not completely selected. Just the text area.

I have tried to write myself my macro but it did not work. I get errors because I am mixing methods from calc and writer

Code: Select all

ThisComponent.CurrentSelection.getRangeAddress 
seems not working on text table.

I have no idea how to select completly the currrent cell as I can do with the mouse cursor ( not only the text region ).
I suppose that I must fix the background color of the entire cell and then fix the background color of the text region and then the highlight color and finish with the character color.

By the way how can I get the coordinate of the current cell.

Thank you for helping me.
Last edited by Hagar Delest on Fri Mar 23, 2012 12:44 am, edited 1 time in total.
Reason: tagged [Solved].
openoffice 3.4.5 - opensuse 12.1 - winxp pro
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Writer macro to select entire cell in text table

Post by JohnSUN-Pensioner »

Wellcome!

Code: Select all

Sub CellOfTable
Dim oTextTables As Variant	' All tables of document
Dim oTextTable As Variant	' One table
Dim oCell As Variant		' One cell
	oTextTables = ThisComponent.getTextTables()
	oTextTable = oTextTables.getByIndex(0)	
REM or	oTextTable = oTextTables.getByName("Table2")
	
	oCell = oTextTable.getCellByPosition(1, 2)
REM or	oCell = oTextTable.getCellByName("B3") - see name of cell in StatusBar
	oCell.setPropertyValue("BackColor", RGB(255, 255, 0))	' or any other
End Sub
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writer macro to select entire cell in text table

Post by Villeroy »

Code: Select all

Sub Main
view = ThisComponent.getCurrentController()
cursor = view.getViewCursor()
cell = cursor.Cell
print cell.CellName
End Sub
The Cell property is void (Basic Empty) when the cursor is outside a table.
The resulting cell is unclear to me when more than one cell is selected. It is not necessarily the cell with the text cursor.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Writer macro to select entire cell in text table

Post by JohnSUN-Pensioner »

I mean this
NameOfCell.PNG
NameOfCell.PNG (4.6 KiB) Viewed 10200 times
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
jcdole
Posts: 4
Joined: Wed Mar 14, 2012 3:17 pm

Re: Writer macro to select entire cell in text table

Post by jcdole »

Hello.
I will try this and give you news.

Than you.
openoffice 3.4.5 - opensuse 12.1 - winxp pro
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writer macro to select entire cell in text table

Post by Villeroy »

When the selection includes more than one cell, the selection has interface com.sun.star.text.XTextTableCursor with property RangeName (A1:D5 without table name).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jcdole
Posts: 4
Joined: Wed Mar 14, 2012 3:17 pm

[Solved] Writer macro to select entire cell in text table

Post by jcdole »

Hello.

What I have used :

Code: Select all

sub TXT_Blanc_MagentaClair
rem -------------------ALT+1---------------------------------------------------
rem define variables

  Dim the_Cursor	As Object 
  Dim the_CurCell	As Object

  the_CurCell=thisComponent.currentSelection(0).cell
  the_Cursor=the_CurCell.CreateTextCursorByRange(the_CurCell.start)
  the_Cursor.GoToEnd true 'le curseur recouvre toute la cellule

  the_CurCell.setPropertyValue("BackColor", 16711935) ' Magenta clair / Light Magenta
  
  With the_Cursor
rem      .charBackColor=
      .charBackTransparent=True 'Reset de la couleur de surbrillance / No Hightlighting
      .charColor=16777215 'couleur des caractères : BLANC / WHITE
      .charOverLine=0 'style de surlignage : AUCUN / NONE
rem      .charOverLineColor=
  End With

end sub
Thank you for helping.
openoffice 3.4.5 - opensuse 12.1 - winxp pro
jcdole
Posts: 4
Joined: Wed Mar 14, 2012 3:17 pm

[Solved] Writer macro to select entire cell in text table

Post by jcdole »

This thgread is solved.

Thank you for helping
openoffice 3.4.5 - opensuse 12.1 - winxp pro
Post Reply