急请教bcb的一个问题
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Variant vExcelApp,vExcelApp2, vWorkbook, vRange,vWorkbook2,vsheet1,vsheet2;
try
{
vExcelApp = Variant::CreateObject ("Excel.Application");
vExcelApp2 = Variant::CreateObject ("Excel.Application");
}
catch(...)
{
ShowMessage("运行Excel出错,请确认安装了Office");
return;
}
int line1,row1,line2,row2;
/ Workbook = vExcelApp.PG("ActiveWorkBook");
/ ExcelApp = Variant::CreateObject("Excel.Application");
//第一张表
vExcelApp2.OlePropertySet("Visible", false);
vExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open", filename1.c_str());
vWorkbook = vExcelApp.OlePropertyGet("ActiveWorkbook");
vsheet1 = vWorkbook.PG("ActiveSheet");
line1=vsheet1.PG("UsedRange").PG("Columns").PG("Count"); //列数
row1=vsheet1.PG("UsedRange").PG("Rows").PG("Count"); //行数
// Variant Range1;
//Range1 = vsheet1.PG("Range","A2:A&row1");
//第二张表
vExcelApp2.OlePropertySet("Visible", false);
vExcelApp2.OlePropertyGet("WorkBooks").OleProcedure("Open", filename2.c_str());
vWorkbook2 = vExcelApp2.OlePropertyGet("ActiveWorkbook");
vsheet2 = vWorkbook2.PG("ActiveSheet");
line2=vsheet2.PG("UsedRange").PG("Columns").PG("Count"); //列数
row2=vsheet2.PG("UsedRange").PG("Rows").PG("Count");
//行数
// Variant Range2;
// Range2 = vsheet1.PG("Range","A2:A&row2");
//下面进行比较
int i,j,k,m;
for(i=2;i<=row1;i++)
for(k=2;k<=row2;k++)
{
String strValue1 = vsheet1.PG("Cells", i, j).PG("Value");
String strValue2 = vsheet2.PG("Cells", i, j).PG("Value");
if(strValue1==strValue2)
{ for(j=1;j<=line1;)
{if((vsheet1.PG("Cells", i, j).PG("Value")==vsheet2.PG("Cells", i, j).PG("Value"))&(j==line1))
{String strValue = "相同";
vsheet1.PG("Cells",i, line1+1).PS("Value", strValue.c_str());
vsheet2.PG("Cells",k, line2+1).PS("Value", strValue.c_str());
}
else{j++;}
}
}
else //(vsheet1.PG("Cells", i, j).PG("Value")!=vsheet2.PG("Cells", i, j).PG("Value"))
{String strValue2 = "不同";
vsheet1.PG("Cells",i, line1+1).PS("Value", strValue2.c_str());
vsheet2.PG("Cells",k, line2+1).PS("Value", strValue2.c_str());
break;
}
vWorkbook.OleProcedure("Save");
vWorkbook.OleProcedure("Close");
vExcelApp.OleFunction("Quit");
vWorkbook = Unassigned;
vExcelApp = Unassigned;
vWorkbook2.OleProcedure("Save");
vWorkbook2.OleProcedure("Close");
vExcelApp2.OleFunction("Quit");
vWorkbook2 = Unassigned;
vExcelApp2 = Unassigned;
ShowMessage("ok");
}
}
这只是程序一部分,由于篇幅有限,头文件和说明参数文件没有给出。在c++buider6运行通过,但是程序用按钮打开两个excel表进行比较时,出现project are raised exception class eolesyserror with message "发生意外".process stopped.
use step or run to continue.
请教是什么问题