views:

368

answers:

2

Hello could someone please help me with the following: I want to center the text in a scalc open office spreadsheet cell via Delphi and the OOoTools toolkit.

The following code does not work:

sRange := '$A$3:$A$3';
ooParams := CreateUnoStruct('com.sun.star.beans.PropertyValue', 1);
ooParams[0].Name  := 'ToPoint';
ooParams[0].Value := sRange;
execDispatch('.uno:GoToCell', ooParams);

ooParams := CreateUnoStruct('com.sun.star.beans.PropertyValue', 1);
ooParams[0].Name  := 'HorizontalJustification';
ooParams[0].Value := 'com.sun.star.table.CellHoriJustify.CENTER';
execDispatch('.uno:HorizontalJustification', ooParams);

Has someone any idea why not? Thanks Ad

A: 

Are you sure the parameter is called 'HorizontalJustification', and not 'HoriJustify'?

Paul-Jan
Thanks for your time but that does not seem to be significant, regards Ad
addelichtman
+1  A: 

It seems that HorizontalJustification needs an enumvalue, but you're giving a string. You have to lookup the value of com.sun.star.table.CellHoriJustify.CENTER and fill your ooParams[0].Value with it.

Here is a way to lookup an enumvalue: http://www.oooforum.org/forum/viewtopic.phtml?t=16383

In your case com.sun.star.table.CellHoriJustify.CENTER equals 2, so you need:

ooParams[0].Name  := 'HorizontalJustification';
ooParams[0].Value := 2;
The_Fox
Thank you very much for your time, that works, also I had to fill in a 0 for the last parameter in: ooParams := CreateUnoStruct('com.sun.star.beans.PropertyValue', 0);Kind Regards Ad.
addelichtman
The last parameter of CreateUnoStruct specifies the maximum index of the sequence (VarArray) you want to create. So when you say 1, you get a VarArray with 2 elements [0..1], but you only need 1 element [0..0], so maximumindex is 0.
The_Fox