Thanks Peter, exactly what I needed.  And here's the code snippet in case
anyone else needs it:

// Query the number formats supplier of the spreadsheet document
com.sun.star.util.XNumberFormatsSupplier xNumberFormatsSupplier =
(com.sun.star.util.XNumberFormatsSupplier)
UnoRuntime.queryInterface(com.sun.star.util.XNumberFormatsSupplier.class,
                                xSpreadSheetDoc);

// Get the number formats from the supplier
com.sun.star.util.XNumberFormats xNumberFormats =
xNumberFormatsSupplier.getNumberFormats();

XCell xCell = xSheet.getCellByPosition(2, 3); // just one cell as an example

logger.debug("**** " + xCell.getFormula().toString());
                    
// Query the property set of the cell
com.sun.star.beans.XPropertySet xCellProp =
(com.sun.star.beans.XPropertySet)
UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
                            xCell);

// Get the number format index key of the cell's properties
int nIndexKey = ((Integer) xCellProp.getPropertyValue(
                            "NumberFormat")).intValue();

// Get the properties of the number format
com.sun.star.beans.XPropertySet xProp = xNumberFormats.getByKey(nIndexKey);

// Get the format code string of the number format's properties
String aFormatCode = (String) xProp.getPropertyValue("FormatString");

logger.debug("FormatString: `" + aFormatCode + "'");
                    
// note the empty locale for default locale
com.sun.star.lang.Locale aLocale = new com.sun.star.lang.Locale();

// Query the XNumberFormatTypes interface
com.sun.star.util.XNumberFormatTypes xNumberFormatTypes =
(com.sun.star.util.XNumberFormatTypes)
UnoRuntime.queryInterface(com.sun.star.util.XNumberFormatTypes.class,
                            xNumberFormats);
                    
int nDateTimeKey =
xNumberFormatTypes.getStandardFormat(com.sun.star.util.NumberFormat.DATETIME
,aLocale);

logger.debug("nDateTime = " + nDateTimeKey);
                    
// Set number format to default currency
xCellProp.setPropertyValue("NumberFormat", new Integer(nDateTimeKey));

_______________________
Anh-Tuan Le
FCI

-----Original Message-----
From: Peter Eberlein [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 24, 2007 2:18 AM
To: [email protected]
Subject: Re: [api-dev] Calc: setting a date format column (JAVA)

Anh-Tuan Le schrieb:
> Ok, so I got this...
> 
> xCell.setFormula("=DATE(1980;12;24;)");  // for example
> 
> but what I'd like to do is have a date forumat column that looks like
> 
> Apr 20, 2007 4:19:00 PM
> 
> Anyone have any ideas?
> 
http://api.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.xhtml#1_2
_5_Number_Formats
A date format is a number format. Please define your preferred format 
and read it out.

Hope that helps,

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to