OLE控制Excel的问题 (OlePropertySet异常)
开发环境:
WinXP Pro版
C++Builder 6.0企业版
在使用OLE提取Excel文件数据时,发生访问违例异常!
程序代码如下:
TOpenDialog * dlg=new TOpenDialog(this);
dlg->Filter="Excel文件(.xls)|*.xls";
if(dlg->Execute())
{
Variant Ex,Wk,Sheet,Sh1;
Ex=Variant::CreateObject("Excel.Application");
____________________________________
Ex.OlePropertySet("Visible",false);
_______________________________________
Ex.OlePropertyGet("WorkBooks").OleProcedure("Open",dlg->FileName.c_str(),false,0);
Wk=Ex.OlePropertyGet("ActiveWorkBook");
Sheet=Wk.OlePropertyGet("Sheets");
int nCount=Sheet.OlePropertyGet("Count");
ShowMessage(nCount);
for(int i=0;i<nCount;i++)
{
Sheet.OlePropertyGet("Item",i+1).OleProcedure("Select");
ShowMessage(Wk.OlePropertyGet("ActiveSheet").OlePropertyGet("Name"));
}
Ex.OleFunction("Quit");
}
问题:
以上代码在一个新建的工程中能够正常运行,然将其移值至一MDI工程中时
---------------------------------------
程序运行至
Ex.OlePropertySet("Visible",false);
即发生访问违例异常(AV)
哪位大虾碰到过这种情况的,请指教?