Board index » cppbuilder » Using TExcelApplication to Open a Workbook

Using TExcelApplication to Open a Workbook


2003-10-21 05:57:58 AM
cppbuilder63
Hello All,
I'm writing a BCB app that should open an existing Excel (2000) workbook. I
use TExcelApplication to do this, but am getting errors when I call the open
method. The code I'm using, although perhaps a bit roundabout, seems like
it should work. The error occurs when the Open method is called, and the
error message is totally unhelpful. Any help is appreciated.
Regards,
Todd Eischeid
***************************
char tmp[200];
wchar_t wtmp[200];
//Edit1->Text is a valid Excel file name
strcpy(tmp, Edit1->Text.c_str());
mbstowcs(wtmp, tmp, strlen(tmp) + 1);
//ERROR OCCURS HERE!
ExcelApplication1->Workbooks->Open(wtmp);
*************************************
 
 

Re:Using TExcelApplication to Open a Workbook

Quote
char tmp[200];
wchar_t wtmp[200];

//Edit1->Text is a valid Excel file name
strcpy(tmp, Edit1->Text.c_str());
mbstowcs(wtmp, tmp, strlen(tmp) + 1);


//ERROR OCCURS HERE!
ExcelApplication1->Workbooks->Open(wtmp);


try this:
BSTR _filename = StringToOleStr("your file");
XlApplication->Workbooks->Open(_filename);
Best regards
Bye from XXXX@XXXXX.COM
 

Re:Using TExcelApplication to Open a Workbook

Igor,
Thanks a bunch!! Your tip works like a charm.
Todd
"Igor Tsukanov" < XXXX@XXXXX.COM >wrote in message
Quote

>char tmp[200];
>wchar_t wtmp[200];
>
>//Edit1->Text is a valid Excel file name
>strcpy(tmp, Edit1->Text.c_str());
>mbstowcs(wtmp, tmp, strlen(tmp) + 1);
>
>
>//ERROR OCCURS HERE!
>ExcelApplication1->Workbooks->Open(wtmp);
>
>

try this:

BSTR _filename = StringToOleStr("your file");

XlApplication->Workbooks->Open(_filename);

Best regards
Bye from XXXX@XXXXX.COM
 

{smallsort}

Re:Using TExcelApplication to Open a Workbook

Quote
Thanks a bunch!! Your tip works like a charm.
Apropos, The MSDN is superior documentation for work with subj and other MS products. Try to do some macros in Excel(for examp.) and you gotted as result a simply method for using one in Cbuilder.
P.S. Sorry for my english
Best regards
Bye from XXXX@XXXXX.COM