How to display strings like TRUE, 100 as String types..

S

Somashekhar

Hi,

I am using excel's OLE automation and COM to display
widechar strings on excel. When I send a Variant of type
BSTR and BSTR value "TRUE", or "100", "FALSE", etc. to
display on excel sheet, excel automatically converts it to
type binary or number. If I read the same cell, I get back
the Variant of type boolean or int. Is there a way to turn
this "OFF".

If I use Excel SDK then these strings get displayed
perfectly without any conversion. Is there something I am
missing ? A code sample would be helpful.

VARIANT var;
var.vt = VT_BSTR;
var.bstrVal = SysAllocString("TRUE");
dispidPut = DISPID_PROPERTYPUT;
dispparams.cArgs = 1;
dispparams.rgvarg = &var;
dispparams.cNamedArgs = 1;
dispparams.rgdispidNamedArgs = &dispidPut;

// Invoke PropertyPut
//pDispRange is handle to range object

hr = pDispRange->Invoke(dispidValue, IID_NULL,
LOCALE_USER_DEFAULT,DISPATCH_METHOD | ISPATCH_PROPERTYPUT,
&dispparams,NULL, &excep, &uiArgErr));


Thanks,
Som
 
J

Jim Vita

Hi Som,

I think you'll find that although Excel may be displaying TRUE in the
second example, that this value is actually a boolean value and not a
string.

Thanks,

Jim

Jim Vita
Microsoft Developer Support

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026? If not Microsoft strongly advises you to review
the information at the following link regarding Microsoft Security Bulletin
MS03-026 http://www.microsoft.com/security/security_bulletins/ms03-026.asp
and/or to visit Windows Update at http://windowsupdate.microsoft.com to
install the patch. Running the SCAN program from the Windows Update site
will help to insure you are current with all security patches, not just
MS03-026.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Somashekhar

Hi Jim,
That's true that even if I send TRUE as string type, it
gets displayed as type boolean. How to avoid this. I want
to display it as type String not boolean. And also if I
read back that cell, I need to get the data type as String.

- Som


-----Original Message-----

Hi Som,

I think you'll find that although Excel may be displaying TRUE in the
second example, that this value is actually a boolean value and not a
string.

Thanks,

Jim

Jim Vita
Microsoft Developer Support

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026? If not Microsoft strongly advises you to review
the information at the following link regarding Microsoft Security Bulletin
MS03-026 http://www.microsoft.com/security/security_bulletins/ms03-
026.asp
and/or to visit Windows Update at
http://windowsupdate.microsoft.com to
 
J

Jim Vita

Hi Som,

Unfortunately, the data stored in cells are treated as variants. If you put
the string TRUE into the cell, it will get converted to its variant value.
Likewise when you extract the value, I think your only way out is to test
and translate the value in your program.

On the other hand, you could try extracting the range as a comma delimited
file and parsing the file. That would get you strings.

Thanks,

Jim

Jim Vita
Microsoft Developer Support

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026? If not Microsoft strongly advises you to review
the information at the following link regarding Microsoft Security Bulletin
MS03-026 http://www.microsoft.com/security/security_bulletins/ms03-026.asp
and/or to visit Windows Update at http://windowsupdate.microsoft.com to
install the patch. Running the SCAN program from the Windows Update site
will help to insure you are current with all security patches, not just
MS03-026.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy Meister -WordMVP-

Hi Somashekhar,

You'll need to CONVERT the values to strings. If this were a
VB language, that would be: CStr(boolVal), for example.
That's true that even if I send TRUE as string type, it
gets displayed as type boolean. How to avoid this. I want
to display it as type String not boolean. And also if I
read back that cell, I need to get the data type as String.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top