OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Formatting XCell

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
mcdermotc
Newbie
Newbie


Joined: 30 Sep 2004
Posts: 4

PostPosted: Thu Sep 30, 2004 12:12 pm    Post subject: Formatting XCell Reply with quote

I am trying to format the Horizotal Alignment in an XCell from a XTextTable. However, whenever I try to set the HoriJustify property, the property does not exist. What object can I reference to set this property? Here is the code.

public static void alignCell( XTextTable TT) {

XCell cell = TT.getCellByName("A1");

XPropertySet xCellProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, cell);

try {

xCellProps.setPropertyValue("HoriJustify", com.sun.star.table.CellHoriJustify.LEFT);

} ....
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Sep 30, 2004 1:38 pm    Post subject: Reply with quote

By using Xray....
Code:
Sub Main
   oDoc = ThisComponent
   oTextTables = oDoc.getTextTables()
   oTable1 = oTextTables.getByIndex( 0 )
   
   oCell = oTable1.getCellByPosition( 0, 1 )
'   oCell.BackColor = RGB( 255, 255, 220 ) ' piss yellow
'   oCell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT

   oCell = oTable1.getCellByName( "A1" )
'   oCell.BackColor = RGB( 150, 200, 50 ) ' snot green

   GlobalScope.BasicLibraries.loadLibrary( "Xray" )
   Xray.Xray oCell
   
   Print oCell.HoriJustify
   oCell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
End Sub


you can discover that the cell you get back has

com.sun.star.text.CellProperties

which is not the same as

com.sun.star.table.CellProperties

The former does not have HoriJustify. The latter does. Sadly.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
mcdermotc
Newbie
Newbie


Joined: 30 Sep 2004
Posts: 4

PostPosted: Thu Sep 30, 2004 2:09 pm    Post subject: Reply with quote

I am using java for this. I have tried querying the interface to no avail.
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Oct 01, 2004 7:13 am    Post subject: Reply with quote

I understood that you are using Java.

I gave a Basic example, which you can run, which will proove beyond any doubt that the com.sun.star.text.CellProperties interface is implemented by this cell rather than the com.sun.star.table.CellProperties interface. The former does not have HoriJustify. The latter does. Sadly.

Querying the interface doesn't matter. Baisc queries the interface. Python queries the interface. (They just do it for you rather than making you do it.)

Querying the interface is irrelevant. The Cell object does NOT have the service you want, and therefore does not have the property you want. You can query for the XPropertySet interface, and get it. But since the property you want is not present in the Cell, calling setPropertyValue, getPropertyValue (on "HoriJustify") is useless because there ain't no such property ("HoriJustify"). (i.e. there is not any such property.)
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
mcdermotc
Newbie
Newbie


Joined: 30 Sep 2004
Posts: 4

PostPosted: Tue Oct 26, 2004 3:33 pm    Post subject: Reply with quote

Sorry, my really question is: how do I call the Xray from Java? I have the macro installed but cannot seem to get the right object back.
Back to top
View user's profile Send private message
mcdermotc
Newbie
Newbie


Joined: 30 Sep 2004
Posts: 4

PostPosted: Tue Oct 26, 2004 4:08 pm    Post subject: Reply with quote

The other issue is - I installed the macro and ran your program and it could not find the property either? Is 4.0 Xray different? Crying or Very sad
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Tue Oct 26, 2004 5:56 pm    Post subject: Reply with quote

Just a guess:
Did you load the Xray library before you tried to use it?

Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Oct 27, 2004 6:02 am    Post subject: Reply with quote

mcdermotc wrote:
The other issue is - I installed the macro and ran your program and it could not find the property either? Is 4.0 Xray different? Crying or Very sad


That is because the property is not there, as I have explained.

Let me try to put it as simply as possible: The cell does not have a HoriJustify property. No matter what tool you use to inspect the service, it is not going to show you a property which is not there. Any future or past version of Xray is not going to cause a new property to appear in the service.

I was unaware of Xray 4.0. Just downloaded it. Now installing it. Upgrading from Xray 2.0. Thanks.


Cybb20 wrote:
Just a guess:
Did you load the Xray library before you tried to use it?


In my macro code above, I deliberately included a line to load Xray. The purpose of that macro was to proove beyond any doubt that the service does not include the property HoriJustify. Instead of using Xray, I suppose I could have written a loop which would produce a Writer document showing the properties in the service.

In a TextTable, the cells have com.sun.star.text.CellProperties.
In a Spreadsheet, the cells have com.sun.star.table.CellProperties.

TextTable cells do not have HoriJustify. Anyone who is brave enough to click on the two links I provided (and earlier) can see that one type of cell has HoriJustify, and the other does not.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
_matt
General User
General User


Joined: 28 Oct 2004
Posts: 10
Location: Germany

PostPosted: Thu Oct 28, 2004 5:09 am    Post subject: Reply with quote

Hi,
have had the same problem and this is the solution:

Code:

for(int i=1;i<=rowCount;i++)
{
    for(int k=0;k<columnCount;k++)
    {
          char ch = 65;
          ch += k
          String cellName = "" + ch + i;

          XText xCellText = (XText) UnoRuntime.queryInterface(
                           XText.class, xTable.getCellByName(cellName));

          XTextCursor textCursor = xCellText.createTextCursor();
         
          XParagraphCursor xParaCursor = (XParagraphCursor)           
                     UnoRuntime.queryInterface(
                               XParagraphCursor.class, textCursor );
       
          XPropertySet paraProps = (XPropertySet)             
                     UnoRuntime.queryInterface(
                               XPropertySet.class, xParaCursor);

          paraProps.setPropertyValue ( "ParaAdjust",
                     com.sun.star.style.ParagraphAdjust.LEFT );
    }
}

and here is the link to the available properties:
http://api.openoffice.org/docs/common/ref/com/sun/star/style/ParagraphProperties.html

_matt Smile
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Oct 28, 2004 6:36 am    Post subject: Reply with quote

That is a good solution. Completely different approach.

Rather than trying to adjust the cell properties, you adjust the paragraph properties of the text of the cell.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Oct 28, 2004 8:53 am    Post subject: Reply with quote

Because people are speaking on XRay and Java.
I think it is possible to call XRay from Java, but you need an add-on. I will try to do it in C++ but I don't know when.
I have read in the developper's guide it a Java program given with SDK allows Object exploration. I have never seen this program with SDK. Have any body seen it ?
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
rommie
General User
General User


Joined: 16 Dec 2004
Posts: 5

PostPosted: Thu Jan 13, 2005 2:25 am    Post subject: VB - How to format cell Reply with quote

Is there sample VB on how to this?

Im looking for on how to merge cells, align cell, change number format, hide column or row
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Jan 13, 2005 9:00 am    Post subject: Reply with quote

A tutorial for Programming OpenOffice.org with Visual Basic http://www.oooforum.org/forum/viewtopic.php?t=11854&highlight=
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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