Delphi中怎么导出TwwoDBGrid中的数据。,学的不是Delphi 但是现在有个程序需要修改下。。就是导出TwwDBGrid中的数据。没使用Delphi导出过。。有高手给个势力或者代码的吗??什么都不要只要导出TwwDBGrid中的数据成Excel就行了 

解决方案 »

  1.   

    不知道TwwDBGrid本身是否 提供导出方法,如果没有,就是循环数据集然后写道excel中,具体的去查delphi操作excel资料
      

  2.   

    var
      i,n: Integer;
      xlsApp: Variant;
    begin
      if adsMaster.Eof then begin
        ShowMessage('没有数据!');
        exit;
      end;
      xlsApp := CreateOleObject('Excel.Application');
      xlsapp.WorkBooks.add;
      xlsApp.Visible := false;
      xlsApp.WorkSheets[1].Activate;
      adsMaster.First;
      i :=1;
      //填Excel标题行
      for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel;
      While not adsMaster.Eof do begin
        inc(i);//因在循环前使用了一次填标题行,所以在前面做增量
        for n:=1 to adsMaster.FieldCount do begin
          if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString
          else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString;
        end;
        adsMaster.Next;
      end;
      xlsApp.Visible := true;
    上面是我找的资料但是看不明白是什么意思。。能帮我解释下吗 ?
      

  3.   


    var
      i,n: Integer;
      xlsApp: Variant;
    begin
      //判断adsMaster数据集是否为空
      if adsMaster.Eof then begin
      ShowMessage('没有数据!');
      exit;
      end;
      //创建excel原生对象
      xlsApp := CreateOleObject('Excel.Application');
      xlsapp.WorkBooks.add;
      xlsApp.Visible := false;
      //激活sheet1
      xlsApp.WorkSheets[1].Activate;
      //adsMaster指向第一条
      adsMaster.First;
      i :=1;
      //填Excel标题行,Cells是单元格集合
      for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel;
      //循环adsMaster
      While not adsMaster.Eof do begin
      inc(i);//因在循环前使用了一次填标题行,所以在前面做增量
      for n:=1 to adsMaster.FieldCount do begin
      if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString
      else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString;
      end;
      adsMaster.Next;
      end;
      //显示excel
      xlsApp.Visible := true;
    end.
      

  4.   

    这些代码可以直接用吗。?为什么我允许到
     xlsApp := CreateOleObject('Excel.Application');
    这里就出错了