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

Keyboard macros or custom scripts

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

Postby jcdole » Wed Mar 14, 2012 7:34 pm

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   Expand viewCollapse view
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
jcdole
 
Posts: 4
Joined: Wed Mar 14, 2012 3:17 pm

Re: Writer macro to select entire cell in text table

Postby JohnSUN-Pensioner » Wed Mar 14, 2012 8:32 pm

Wellcome!
Code: Select all   Expand viewCollapse view
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
JohnSUN-Pensioner
Volunteer
 
Posts: 862
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Writer macro to select entire cell in text table

Postby Villeroy » Wed Mar 14, 2012 9:10 pm

Code: Select all   Expand viewCollapse view
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
Villeroy
Volunteer
 
Posts: 30288
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writer macro to select entire cell in text table

Postby JohnSUN-Pensioner » Wed Mar 14, 2012 9:30 pm

I mean this
NameOfCell.PNG
NameOfCell.PNG (4.6 KiB) Viewed 9094 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
User avatar
JohnSUN-Pensioner
Volunteer
 
Posts: 862
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Writer macro to select entire cell in text table

Postby jcdole » Wed Mar 14, 2012 9:38 pm

Hello.
I will try this and give you news.

Than you.
openoffice 3.4.5 - opensuse 12.1 - winxp pro
jcdole
 
Posts: 4
Joined: Wed Mar 14, 2012 3:17 pm

Re: Writer macro to select entire cell in text table

Postby Villeroy » Wed Mar 14, 2012 9:57 pm

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
User avatar
Villeroy
Volunteer
 
Posts: 30288
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby jcdole » Tue Mar 20, 2012 1:32 pm

Hello.

What I have used :

Code: Select all   Expand viewCollapse view
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

Postby jcdole » Thu Mar 22, 2012 11:39 pm

This thgread is solved.

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


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 4 guests