UNO API

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

UNO API

k.misha
Hi!

 

I have a problem using this code:

 

#define S_CURRENCY 106 // DOESN'T WORK =(

#define S_PERCENT_SHORT 10 // 123%

#define S_PERCENT 11 //123.00%

#define S_DEFAULT 0

 

 

      Reference< XSpreadsheet > rSpSheet (rSheet, UNO_QUERY);

      Reference< XCell > rCell = rSpSheet->getCellByPosition(0, 0);

      Reference< XPropertySet > xPropSet(rCell, UNO_QUERY);

 

 
xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("NumberForma
t")), makeAny(S_CURRENCY));

 

 

All other properties(S_PERCENT_SHORT,S_PERCENT,S_DEFAULT) works greatly!
Only currency doesn't work =( What I'm doing wrong?

 

Thanks!

 

 

Reply | Threaded
Open this post in threaded view
|

Re: UNO API

jg-2
Maybe this helps a bit:

(1) Get access to known types (here only currency and date):
...
// Query the number formats supplier of the writer document
Reference < XNumberFormatsSupplier >
xNumberFormatsSupplier(xTemplateComponent, UNO_QUERY_THROW);
Reference < XNumberFormats > xNumberFormats =
xNumberFormatsSupplier->getNumberFormats();
// Query the XNumberFormatTypes interface
Reference < XNumberFormatTypes > xNumberFormatTypes(xNumberFormats,
UNO_QUERY_THROW);
// Get the number format index key of the default currency format, note
the empty locale for default locale
Locale aLocale;
m_nCurrencyKey =
xNumberFormatTypes->getStandardFormat(com::sun::star::util::NumberFormat::CURRENCY,
aLocale);
m_nDateKey =
xNumberFormatTypes->getStandardFormat(com::sun::star::util::NumberFormat::DATE,
aLocale);
....

(2) Later: set the cell properties:
...
switch (dataType) {
case UnoDataType::CurrencyType:
     xCellProps->setPropertyValue(L"NumberFormat",
Any((sal_Int32)m_nCurrencyKey));
     xCellCursorProps->setPropertyValue(L"ParaAdjust",
Any(com::sun::star::style::ParagraphAdjust_RIGHT));
     break;
...
}

I am working with a table inside a writer document, but the spreadsheet
shouldn't differ a lot.

Yes, I do know that this may not be portable, but the rest of the MFC
sources isn't either :)

jg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: UNO API

Ariel Constenla-Haile-2
In reply to this post by k.misha
Hi k.misha,

On Thu, Apr 18, 2013 at 11:00:00PM +0300, k.misha wrote:

> Hi!
>
>  
>
> I have a problem using this code:
>
>  
>
> #define S_CURRENCY 106 // DOESN'T WORK =(
>
> #define S_PERCENT_SHORT 10 // 123%
>
> #define S_PERCENT 11 //123.00%
>
> #define S_DEFAULT 0
>
>  
>
>  
>
>       Reference< XSpreadsheet > rSpSheet (rSheet, UNO_QUERY);
>
>       Reference< XCell > rCell = rSpSheet->getCellByPosition(0, 0);
>
>       Reference< XPropertySet > xPropSet(rCell, UNO_QUERY);
>
>  
>
>  
> xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("NumberForma
> t")), makeAny(S_CURRENCY));
>
>  
>
>  
>
> All other properties(S_PERCENT_SHORT,S_PERCENT,S_DEFAULT) works
> greatly!  Only currency doesn't work =( What I'm doing wrong?
These constants are bad, you should use the number formats API:

http://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Number_Formats
"Number formats are defined on the document level. A document displaying
formatted values has a collection of number formats, each with a unique
index key within that document. Identical formats are not necessarily
represented by the same index key in different documents."

Note the "not necessarily". This means, you have to use
http://www.openoffice.org/api/docs/common/ref/com/sun/star/util/XNumberFormats.html
http://www.openoffice.org/api/docs/common/ref/com/sun/star/util/XNumberFormatTypes.html
as explained here
http://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Managing_Number_Formats

See the code attached for an example.


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

Makefile (3K) Download Attachment
main.cxx (8K) Download Attachment
attachment2 (853 bytes) Download Attachment