首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

打开excel文件出现有关问题,请高手指教

2012-03-16 
打开excel文件出现问题,请高手指教程序:__fastcallTForm1::TForm1(TComponent*Owner):TForm(Owner){}//---

打开excel文件出现问题,请高手指教
程序:

__fastcall   TForm1::TForm1(TComponent*   Owner)
                :   TForm(Owner)
{
}
//---------------------------------------
void   __fastcall   TForm1::Button1Click(TObject   *Sender)
{
Variant   ex,Wb,Sh1;
try
{
ex=Variant::CreateObject( "Excel.Application ");   //启动Excel
}
catch(...)
{
ShowMessage( "无法启动Excel ");
}
ex.OlePropertyGet( "WorkBooks ").OleProcedure( "Open ", "C:\Program   Files\Borland\CBuilder6\Projects\excel\test.xls ");

Wb=ex.OlePropertyGet( "ActiveWorkBook ");   Sh1=Wb.OlePropertyGet( "ActiveSheet ");
Edit1-> Text=Sh1.OlePropertyGet( "Cells ",1,1).OlePropertyGet( "Value ");
for   (int   i=1;i <=10;i++)
                for   (int   j=1;j <=10;j++)
                      Sh1.OlePropertyGet( "Cells ",i,j).OlePropertySet( "Value ",i*100+j);


Wb.OleProcedure( "Save ");   Wb.OleProcedure( "Close ");
}


编译通过,运行时出现以下问题:
Project   excel.exe   raised   exception   class   EOleSysError   with   message   '发生意外 '.   Process   stopped.   Use   Step   or   Run   to   continue.


有问题的语句:
ex.OlePropertyGet( "WorkBooks ").OleProcedure( "Open ", "C:\Program   Files\Borland\CBuilder6\Projects\excel\test.xls ");

请问是什么问题?

[解决办法]
你要看看下面这个写法有没有问题。

"C:\Program Files\Borland\CBuilder6\Projects\excel\test.xls "

是否要用“\\”?
[解决办法]
是路径问题.
"C:\\Program Files\\Borland\\CBuilder6\\Projects\\excel\\test.xls "
[解决办法]
楼上正解:)

热点排行