Page 1 of 1

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

Posted: Wed Mar 14, 2012 7:34 pm
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.

Re: Writer macro to select entire cell in text table

Posted: Wed Mar 14, 2012 8:32 pm
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

Re: Writer macro to select entire cell in text table

Posted: Wed Mar 14, 2012 9:10 pm
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.

Re: Writer macro to select entire cell in text table

Posted: Wed Mar 14, 2012 9:30 pm
by JohnSUN-Pensioner
I mean this
NameOfCell.PNG
NameOfCell.PNG (4.6 KiB) Viewed 10206 times

Re: Writer macro to select entire cell in text table

Posted: Wed Mar 14, 2012 9:38 pm
by jcdole
Hello.
I will try this and give you news.

Than you.

Re: Writer macro to select entire cell in text table

Posted: Wed Mar 14, 2012 9:57 pm
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).

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

Posted: Tue Mar 20, 2012 1:32 pm
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.

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

Posted: Thu Mar 22, 2012 11:39 pm
by jcdole
This thgread is solved.

Thank you for helping