标题:请教一个bcb的问题
只看楼主
lzhigao
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-12-25
 问题点数:0 回复次数:0 
请教一个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.
请教是什么问题
搜索更多相关主题的帖子: bcb 
2007-12-25 11:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-194182-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.189630 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved