加入收藏 最近更新下载
  用户名: 密 码:
三友软件ERP操作问答
三友信息中心
信息搜索
关键字:
范 围:
首页三友信息中心 技术支持其它技术文档
 
DBGrid导出Excel方法
内容来源:其它技术文档    点击数:3890    更新时间:2012/4/24 9:29:55    收藏此页

sp;        begin  

                         //Excel.Columns[k+1].ColumnWidth:=dbgrid.Columns.Items[i].Title.Column.Width;  

                         excel.cells[1,k+1]:=dbgrid.Columns.Items[i].Title.Caption;  

                         inc(k);  

                     end;  

           end;  

   

       dbgrid.DataSource.DataSet.DisableControls;  

       saveplace:=dbgrid.DataSource.DataSet.GetBookmark;  

       dbgrid.DataSource.dataset.First;  

       i:=2;  

       if    dbgrid.DataSource.DataSet.recordcount>65536    then  

             ProgressBar1:=ProgressBarform(65536)  

       else  

             ProgressBar1:=ProgressBarform(dbgrid.DataSource.DataSet.recordcount);  

       while    not    dbgrid.DataSource.dataset.Eof    do  

           begin  

               k:=0;  

               for    j:=0    to    dbgrid.Columns.count-1    do  

                   begin  

                       if    dbgrid.Columns.Items[j].Visible    then  

                             begin  

                                 excel.cells[i,k+1].NumberFormat:='@';  

                                 if    not    dbgrid.DataSource.dataset.fieldbyname(dbgrid.Columns.Items[j].FieldName).isnull    then  

                                       begin  

                                           str:=dbgrid.DataSource.dataset.fieldbyname(dbgrid.Columns.Items[j].FieldName).value;  

                                           Excel.Cells[i,    k    +    1]    :=    Str;  

                                       end;  

                                 inc(k);  

                             end  

                       else  

                             continue;  

                   end;  

               if    i=65536    then  

                     break;  

               inc(i);  

               ProgressBar1.StepBy(1);  

               dbgrid.DataSource.dataset.next;  

           end;  

       progressbar1.Parent.Free;  

   

       dbgrid.DataSource.dataset.GotoBookmark(SavePlace);  

       dbgrid.DataSource.dataset.EnableControls;  

   

       try  

           if    copy(FileName,length(FileName)-3,4)<>'.xls'    then  

                 FileName:=FileName+'.xls';  

           Excel.ActiveWorkbook.SaveAs(FileName,    xlNormal,    '',    '',    False,    False);  

       except  

           Excel.Quit;  

             screen.cursor:=crDefault;  

           exit;  

       end;  

       Excel.Visible    :=    true;  

       screen.cursor:=crDefault;  

       Result    :=    true;  

   end;

 

 

总页数:2  第  1  2    页 

上一篇:没有上一篇资讯了   下一篇:Delphi 实现串口通信
【刷新页面】【加入收藏】【打印此文】 【关闭窗口】
 
友情链接
版权所有 2009 © 深圳市三友信息技术有限公司 网站备案号:粤ICP备20072280号
代理域名注册服务机构:北京新网数码信息技术有限公司