Calc API util.NumberFormatProperties [answered]

Dear Calc community:

In which *.jar file can the class NumberFormatProperties be found?

com.sun.star.util.NumberFormatProperties

http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1util_1_1NumberFormatProperties.html

It is not in the unoil.jar with the other NumberFormat classes.

util.NumberFormat

util.NumberFormatter

util.NumberFormatsSupplier

util.XNumberFormats

util.XNumberFormatter

util.XNumberFormatTypes

util.XNumberFormatsSupplier

util.XNumberFormatPreviewer

It is not in the following *.jar files either.

juh.jar, jurt.jar, ridl.jar

Thanks for guidance.

Sincerely,

MS Windows XP SP3, x32

LO 5.4.7.2, last version for XP

BeanShell 2.0.6

JRE 1.8.0.152 x32

JVM hotspot, not OpenJ9

Perhaps if you read chapter 5.14 Create Number Format Style in Andrew’s book Useful Macro Information For OpenOffice.org, you will find a solution to your problem.

1 Like

Thanks for the tip. util.NumberFormatProperties was not mentioned in the book of BASIC script by Andrew Pitonyak at the time of this writing.

In addition, the access to LO class members differs in BASIC and Java (BeanShell). BASIC allows convenient direct access to LO class members. Unfortunately Java (BeanShell) does not permit such convenience. A convoluted approach is required in Java (BeanShell) to access / retrieve LO class members. An example is provided below.


20150315 How to set number of decimal places and font for a cell in Calc by macro

How to set number of decimal places and font for a cell in Calc by macro

xcell.NumberFormat = …


Notice the above BASIC statement in discussion. Neat and convenient. But this BASIC code would not work in Java. Java (BeanShell) complains “cannot access field NumberFormat on object table.XCell”. Sigh!


Thanks for advice.

com.sun.star.util.NumberFormatProperties is a properties-only service not exporting any method. Those do not have a .class in a .jar

I see. Thanks for the tip.


BeanShell balks at the declaration of NumberFormatProperties variables, despite import com.sun.star.util.NumberFormatProperties;

complaint: NumberFormatProperties not found in name space.


How could one access the below?

  1. short NumberFormatProperties.Type
  2. String NumberFormatProperties.FormatStrng (the string of format code)
  3. String NumberFormatProperties.Comment


I managed to get the FormatString via the following convoluted approach. Apology for the outline instead of code. I do not know how to properly control the html format for code list.

  1. get XNumberFormats from XSpreadsheetDocument,
  2. get format ID (handle) from XCell,
  3. get XPropertySet of the format ID by 1 + 2,
  4. extract the “FormatString” property from 3.


Is NumberFormatProperties or the convoluted approach the preferred way?


Sincerely,

com.sun.star.util.NumberFormatProperties is a com.sun.star.beans.XPropertySet, so that’s how you declare and access it (and probably did already by 3 + 4).

com.sun.star.beans.XPropertySet xProp = xNumberFormats.getByKey( nIndexKey );
String aFormatCode = (String) xProp.getPropertyValue( "FormatString" );

You may call it convoluted, but it is a flexible way to manage number formats.

See also the OOo DevGuide detailed example.

Thanks for API “Applying Number Formats” and the code list. That was how I did it.


Given the following facts:

  1. The NumberFormatProperties class is published in LO API.
  2. The NumberFormatProperties class has no *.class in any LO *.jar file.
  3. not possible to declare NumberFormatProperties variables in Java (BeanShell), due to 2.


I wonder:

  1. Where is the NumberFormatProperties class used?
  2. How to create NumberFormatProperties objects?
  3. How to use NumberFormatProperties?
  4. code illustration, in Java, perhaps in BASIC, or any language.


Thanks for guidance.

As said, NumberFormatProperties is a com.sun.star.beans.XPropertySet returned by com.sun.star.util.XNumberFormats.getByKey() and you can declare it as such just as I showed in my two-lines example above. You can’t create a standalone NumberFormatProperties object, that does not make sense.

Again, see the DevGuide I mentioned Java code example for how to use it and how to create and apply a number format using a format code. And see its previous chapter Managing Number Formats for what to use to, well, manage number formats… and the XNumberFormats and XNumberFormatTypes API documentation.

Noted. Thanks.