| View previous topic :: View next topic |
| Author |
Message |
mcdermotc Newbie

Joined: 30 Sep 2004 Posts: 4
|
Posted: Thu Sep 30, 2004 12:12 pm Post subject: Formatting XCell |
|
|
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 |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Thu Sep 30, 2004 1:38 pm Post subject: |
|
|
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 |
|
 |
mcdermotc Newbie

Joined: 30 Sep 2004 Posts: 4
|
Posted: Thu Sep 30, 2004 2:09 pm Post subject: |
|
|
| I am using java for this. I have tried querying the interface to no avail. |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Fri Oct 01, 2004 7:13 am Post subject: |
|
|
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 |
|
 |
mcdermotc Newbie

Joined: 30 Sep 2004 Posts: 4
|
Posted: Tue Oct 26, 2004 3:33 pm Post subject: |
|
|
| 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 |
|
 |
mcdermotc Newbie

Joined: 30 Sep 2004 Posts: 4
|
Posted: Tue Oct 26, 2004 4:08 pm Post subject: |
|
|
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?  |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Tue Oct 26, 2004 5:56 pm Post subject: |
|
|
Just a guess:
Did you load the Xray library before you tried to use it?
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Wed Oct 27, 2004 6:02 am Post subject: |
|
|
| 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?  |
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 |
|
 |
_matt General User


Joined: 28 Oct 2004 Posts: 10 Location: Germany
|
Posted: Thu Oct 28, 2004 5:09 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
rommie General User

Joined: 16 Dec 2004 Posts: 5
|
Posted: Thu Jan 13, 2005 2:25 am Post subject: VB - How to format cell |
|
|
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 |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
|