You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@openoffice.apache.org by "k.misha" <mi...@4k.com.ua> on 2013/04/04 10:20:04 UTC

uno api problem

Hi! 

 

I have some problems using UNO API! I have this example:

 

Int x = 0;

Int y = 1;

Char * fontName = "Corbel";

Reference< XSpreadsheet > rSpSheet (rSheet, UNO_QUERY);

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

Reference< XPropertySet > xPropSet(rCell, UNO_QUERY);

 

OUString sstring = OUString(RTL_CONSTASCII_USTRINGPARAM(fontName));

xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontNam
e")), makeAny(sstring));

 

But when I look into a cacl document, there is wrong value in cell(0,1). I's
"Cor". But must be "Corbel".

 

Can you help me and show where I'm wrong?

 

Thanks.

 

 


Re: uno api problem

Posted by Ariel Constenla-Haile <ar...@apache.org>.
On Sun, Apr 07, 2013 at 04:06:19PM +0300, k.misha wrote:
> I already fixed this problem this way:
[...]

not portable at all. You may find useful the C++ UNO binding reference:
http://www.openoffice.org/api/docs/cpp/ref/names/index.html


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

RE: uno api problem

Posted by "k.misha" <mi...@4k.com.ua>.
I already fixed this problem this way:<неи<неиint nLenOfWideCharStr =<неи            MultiByteToWideChar(<неи            CP_ACP,<неи            MB_PRECOMPOSED,<неи            fontName,<неи            -1,<неи            NULL,<неи            0<неи        );<неи<неи	wchar_t *cFontName = (PWSTR)HeapAlloc(GetProcessHeap(), 0, nLenOfWideCharStr * sizeof(WCHAR));<неи<неи	MultiByteToWideChar(<неи        CP_ACP,<неи        MB_PRECOMPOSED,<неи        fontName,<неи        -1,<неи        cFontName,<неи        nLenOfWideCharStr<неи    );<неи<неи	OUString sstring = cFontName;<неи<неи    rColProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontName")), makeAny(sstring));<неи<неиThanks :)<неи<неи<неи-----Original Message-----<неиFrom: jg [mailto:jg@jgoettgens.de] <неиSent: Saturday, April 06, 2013 3:15 PM<неиTo: api@openoffice.apache.org<неиSubject: Re: uno api problem<неи<неиThis might also work:<неи<неиxPropertySet->setPropertyValue(L"CharFontName", makeAny(OUString((const <неиsal_Unicode *)L"Corbel")));<неи<неиOr, if the value is not a constant (MFC):<неи<неиCStringW value;<неи...<неиOUString value((const sal_Unicode *)((LPCWSTR)value));<неиxPropertySet->setPropertyValue(L"CharFontName", Any(value));<неи<неи<неи<неиjg<неи<неи---------------------------------------------------------------------<неиTo unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org<неиFor additional commands, e-mail: api-help@openoffice.apache.org<неи<неи

Re: uno api problem

Posted by jg <jg...@jgoettgens.de>.
This might also work:

xPropertySet->setPropertyValue(L"CharFontName", makeAny(OUString((const 
sal_Unicode *)L"Corbel")));

Or, if the value is not a constant (MFC):

CStringW value;
...
OUString value((const sal_Unicode *)((LPCWSTR)value));
xPropertySet->setPropertyValue(L"CharFontName", Any(value));



jg

---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org


Re: uno api problem

Posted by Ariel Constenla-Haile <ar...@apache.org>.
Hi k. misha,

On Thu, Apr 04, 2013 at 11:20:04AM +0300, k.misha wrote:
> Hi! 
> 
>  
> 
> I have some problems using UNO API! I have this example:
> 
>  
> 
> Int x = 0;
> 
> Int y = 1;
> 
> Char * fontName = "Corbel";

Defined this way, fontName is a pointer

> Reference< XSpreadsheet > rSpSheet (rSheet, UNO_QUERY);
> 
> Reference< XCell > rCell = rSpSheet->getCellByPosition(x, y);
> 
> Reference< XPropertySet > xPropSet(rCell, UNO_QUERY);
> 
>  
> 
> OUString sstring = OUString(RTL_CONSTASCII_USTRINGPARAM(fontName));

The macro RTL_CONSTASCII_USTRINGPARAM( constAsciiStr ) expands to

constAsciiStr, ((sal_Int32)(sizeof(constAsciiStr)-1)), RTL_TEXTENCODING_ASCII_US

so that

sizeof( pointer ) - 1

is 4 - 1 (in 32 bit arch.) or 8 - 1 (in 64 bit arch.)

> xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontNam
> e")), makeAny(sstring));
> 
>  
> 
> But when I look into a cacl document, there is wrong value in cell(0,1). I's
> "Cor". But must be "Corbel".

Your OS is 32 bits: (sizeof( pointer ) - 1) is 3, thus "Cor".

 
> Can you help me and show where I'm wrong?

Define the string literal as an array:

const char fontName[] = "Corbel";

or simply avoid all these temporal variables:

xPropSet->setPropertyValue(
OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontName")),
makeAny(OUString(RTL_CONSTASCII_USTRINGPARAM("Corbel"))));



Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina