[Solved] Getproperty value of Table Cell (HoriJustify, ...)

Creating a macro - Writing a Script - Using the API

[Solved] Getproperty value of Table Cell (HoriJustify, ...)

Postby MadhurajN » Thu Sep 03, 2015 8:08 am

I need macro for getproperty value (HoriJustify, VertJustify, Width and CellBackColor) of table cell. If possible help me!!

My code is not working:
Code: Select all   Expand viewCollapse view
Sub gettableproperty
  oDoc = ThisComponent
        for i = 0 to oDoc.getTextTables().Count() - 1
        Dim oTab
        Dim oVCurs
   oDocumentView = oDoc.getCurrentController()
        oTab = oDoc.getTextTables().getByIndex(i)
       Tname = oTab.getName()
       oDoc.getCurrentController().select(oTab)
       oVCurs = oDoc.getCurrentController().getViewCursor()
       oVCurs.goLeft(1, False)
sNames =  oTab.getCellNames()
For j = LBound(sNames) To UBound(sNames)
oTab.getCellByName(sNames(j)).getString(sNames(j))
ocell = oTab.getCellByName(sNames(j))
oViewCursor = ThisComponent.CurrentController.ViewCursor
    oViewCursor.gotoRange(ocell,false)
    oViewCursor.goright(1,true)
    oViewCursor.goleft(1,true)
    oViewCursor.getPropertyValue("BackColor")
Next
Next
End Sub
Last edited by Hagar Delest on Thu Dec 24, 2015 7:05 pm, edited 2 times in total.
Reason: tagged solved
Madhu OpenOffice 3.1 Windows
MadhurajN
 
Posts: 5
Joined: Fri Apr 24, 2015 2:02 pm

Re: Getproperty value (HoriJustify, VertJustify) of Table Ce

Postby MTP » Thu Sep 03, 2015 3:36 pm

Are you working with a Writer document?

When you say the code is "not working", what exactly happens that is different from what you expect? If you get an error message, what does the error message say? What line is highlighted when the code stops?
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
User avatar
MTP
Volunteer
 
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Getproperty value (HoriJustify, VertJustify) of Table Ce

Postby Villeroy » Thu Sep 03, 2015 3:48 pm

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28422
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Getproperty value (HoriJustify, VertJustify) of Table Ce

Postby FJCC » Thu Sep 03, 2015 4:09 pm

I would use code like this to get the background color of cells. I don't see that cells or their text have the properties HoriJustify or VertJustify.
Code: Select all   Expand viewCollapse view
Sub gettableproperty
Dim oTab
Dim oVCurs
oDoc = ThisComponent
for i = 0 to oDoc.getTextTables().Count() - 1
   oTab = oDoc.getTextTables().getByIndex(i)
   Tname = oTab.getName()
   sNames =  oTab.getCellNames()
   For j = LBound(sNames) To UBound(sNames)
      ocell = oTab.getCellByName(sNames(j))
      BkCol = ocell.getPropertyValue("BackColor")
      print BkCol
   Next
Next
End Sub
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7678
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Getproperty value (HoriJustify, VertJustify) of Table Ce

Postby B Marcelly » Thu Sep 03, 2015 7:39 pm

There are properties specific to a text table and others specific to a cell of the table.
Property BackColor is a cell property.
But HoriJustify, VertJustify are not properties of a text table cell. They are properties of a Calc cell.

Justification in a text table cell is handled differently.
What is inside a TextTable Cell ? a text, composed of paragraphs.
The text of a cell is handled exactly like the ordinary text of the Writer document.
Either you will set a specific paragraph style (preferred method), or you will set local formatting. Just like with an ordinary Writer text.
This example centers the text of a cell, assuming there is only one paragraph in the cell.
Code: Select all   Expand viewCollapse view
Dim doc As Object, aTable As Object, aCell As Object
Dim curs As Object, cellText As Object

doc = ThisComponent
aTable = doc.TextTables.getByName("Table1")
aCell = aTable.getCellByName("B2")
' Xray aCell
cellText = aCell.Text
curs = cellText.createTextCursor
' Xray curs
curs.ParaAdjust = com.sun.star.style.ParagraphAdjust.CENTER

You can see, with Xray or MRI, the services supported by a cell text, and by a cursor inside the cell text.
  • A cell supports com.sun.star.text.CellProperties
    This service is different from com.sun.star.table.CellProperties which is supported by a Calc cell.
  • The cursor supports com.sun.star.style.ParagraphProperties (and other services).
  • You can also see that cellText is in fact the same object as aCell. The method getText() is only here to show that you have access to the text of the cell.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Getproperty value (HoriJustify, VertJustify) of Table Ce

Postby MadhurajN » Fri Sep 04, 2015 8:47 am

Thanks every one for your quick attention and suggestions. As per your suggestion I got table cell background colors and horizontal alignments (Left, Center and Right). However I could not get the values of paragraph vertical alignments in TextTable Cell.

I am using ParaVertAlignment Property in this code to fetch the value of vertical alignment, but I got only same value of all the vertical alignments (Top, bottom and Middle).

Below is the code I am using now:

Code: Select all   Expand viewCollapse view
Sub gettableproperty
Dim oTab
Dim oVCurs
oDoc = ThisComponent
for i = 0 to oDoc.getTextTables().Count() - 1
   oTab = oDoc.getTextTables().getByIndex(i)
   Tname = oTab.getName()
   sNames =  oTab.getCellNames()
   For j = LBound(sNames) To UBound(sNames)
      ocell = oTab.getCellByName(sNames(j))
      BkCol = ocell.getPropertyValue("BackColor")
cellText = ocell.Text
curs = cellText.createTextCursor
BkCol1 = curs.ParaAdjust
BkCol2 = curs.ParaVertAlignment
print BkCol
If BkCol1 = 0 Then
      print "para align LEFT"
ElseIf BkCol1 =1 Then
      print "para align RIGHT"
ElseIf BkCol1 =2 Then
      print "para align BLOCK"
ElseIf BkCol1 =3 Then
      print "para align CENTER"
ElseIf BkCol1 =4 Then
      print "para align STRETCH"
EndIf
print BkCol2
   Next
Next
End Sub
Last edited by RoryOF on Fri Sep 04, 2015 5:13 pm, edited 1 time in total.
Reason: Added [code] tags. [RoryOF, Moderator]
Madhu OpenOffice 3.1 Windows
MadhurajN
 
Posts: 5
Joined: Fri Apr 24, 2015 2:02 pm

Re: Getproperty value (HoriJustify, VertJustify) of Table Ce

Postby B Marcelly » Fri Sep 04, 2015 4:35 pm

Please don't forget (Code)...(/Code) in your codes. It's difficult to read without.

With the user interface you click-Right in the cell, choose Cell > Top or Center or Bottom.
So you should look at a cell property.
It is property VertOrient of service com.sun.star.text.CellProperties.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Getproperty value (HoriJustify, VertJustify) of Table Ce

Postby MadhurajN » Mon Sep 07, 2015 8:18 am

That works perfectly, Thank you so much.
Madhu OpenOffice 3.1 Windows
MadhurajN
 
Posts: 5
Joined: Fri Apr 24, 2015 2:02 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests