我的实现代码如下:不懂的地方请提出!procedure TPPms010.LoadExcelFile(FileName:string);
var
  i,j,rows:integer;
  ExcelApp, WorkBook, WorkSheet : Variant;
begin
  inherited;
  cols:=0;
  try
    ExcelApp := CreateOleObject('Excel.Application');
  except
    on E:EolesysError do
    begin
      DispErr(E.Message);
      abort;
    end
    else
    begin
      DispErr('PPMS010-02  Could not Create Excel Application!');
      abort;
    end;
  end;
  try
    try
      ExcelApp.WorkBooks.Open(edtDir.text,,True);
      WorkBook:=ExcelApp.ActiveWorkbook;
      WorkSheet:=WorkBook.ActiveSheet;
    except
      DispInf('PPMS010-01 Can''t open file!', MB_OK + MB_ICONINFORMATION);
      abort;
    end;
    dmppms010.tblAm_allocation_Head.Append ;
    SetHeadValues;                             // set master table field value
    rows:=GetSheetRows(WorkSheet);             
    PrgrsBar.Max:=rows;
    PrgrsBar.step:=1;
    PrgrsBar.Show;
    for i:=1 to rows do
    begin
      dmppms010.tblAm_Allocation_Line.Append;
      SetLineValues;                            //将excel该行数据赋给detail表的各字段
      PrgrsBar.StepIt ;
    end;
  finally
    WorkBook.Close;
    ExcelApp.Quit;
    ExcelApp:= unassigned;
    PrgrsBar.Hide ;
  end;
end;procedure TPPms010.Save;
begin
  with dmPpms010.tblAm_allocation_Head  do
    if not Database.InTransaction  then
      Database.StartTransaction ;
  try
    with dmPpms010.tblAm_allocation_Head do
      if Modified or UpdatesPending then        //modified 为一公用变量,表示表数据是否改动过!
        ApplyUpdates;
    with dmPpms010.tblAm_allocation_Line do
      if Modified or UpdatesPending then
        ApplyUpdates;
    dmPpms010.tblAm_allocation_Line.Database.Commit ;
    dmPpms010.tblAm_allocation_Line.Database.StartTransaction ;
    dmPPms010.Modified :=false;
    sptnSave.Enabled :=false;
  except
    on E:EDBEngineError do
      begin
        dmPpms010.tblAm_allocation_Head.Database.Rollback ;
        Ppms010.ShowError(E);
      end;
  end;
end;

解决方案 »

  1.   

    我认为找出关键字重复的记录是最主要的
    所以我又有了一个建议:
    在table的onposterror事件中将出错的记录以一种格式导出到一个文本文件中,然后继续导下一条记录,导完后,再对那个文本文件中的数据进行编辑,然后再以刚才你在文本文件中认定的那种格式将文本文件中的数据导入数据库
      

  2.   

    11830(其其):
        我在CachedUpdate过程中提交多条数据,怎么样才不中断update忽略错误的一行数据而让其他的数据能够顺利提交?
      

  3.   

    cachedUpdate时 好象posterror 没有触发!
    我在那设置断点,还没有到那就已经有错误了!
    是applyupdates过程引起的!
      

  4.   

    你编辑后到windwos中运行,不要在delphi中运行
      

  5.   

    回(2001-6-28 17:27:01) :
       我怎么去查?关键是我已经导入的数据还在本地缓存中未提交!怎么查询这里面有没有重复记录!
    不会叫我去遍历EXCEL表查吧?
      

  6.   

    回:(2001-6-28 17:50:07)
        在windows中我怎么查错?
      

  7.   

    这是我在table的onposterror事件中显示错误的代码你看看
    procedure Table1postError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    begin
    if (e is EDBEngineError) then
    MyErrMessage((e as EDBEngineError).Errors[0].ErrorCode,'自定义的错误信息');
    end;procedure MyErrMessage(errid:integer;errmessage:string);
    var em:string;
    begin
    ///////////
        case  errid of
              9729:em:='内容不能为空!';
              9730:em:='输入的数值过小!' ;
              9731:em:='输入的数值过大!' ;
              9732:em:='内容不能为空111!' ;
              9740:em:='内容不能为空2222!' ;
        else ;
        em:=errmessage;  //显示自定义的错误信息
        end;
        showmessage(em);
        abort;
    ///////////
    end;
      

  8.   

    可我程序里面没有触发onPostError事件,怎么办?
      

  9.   

    是慢了一点,你看看这种方法行不行,如果发现错误就将出错信息写到文本文件中,继续读下一条excle表中的记录procedure Table1postError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    begin
    if (e is EDBEngineError) then
        //在这里将刚才读到的信息保存到文本文件中
       //加入写文件文件的代码
        abort;
    end;
      

  10.   

    没有触发onPostError事件是什么意思?
      

  11.   

    11830:非常感谢你的关注!
    我先去吃饭了!交个朋友? [email protected]