• DBGridEh 导出数据到EXCEL文件


    在窗体uses中,添加新的引用单元:DBGridEhImpExp

      procedure TFrmdbGridEh.ToolButton2Click(Sender: TObject);

    var
      ExpClass:TDBGridEhExportClass;
      Ext:String;
      lssavedialog: tsavedialog;

    begin

    try
         lssavedialog := tsavedialog.Create(nil);
         lssavedialog.Filter := '*.xls|*.xls|*.csv|*.csv|*.htm|*.htm|*.rtf|*.rtf|*.txt|*.txt';
         lssavedialog.FileName := 'file1';
         if lssavedialog.Execute then
         begin
           case lssavedialog.FilterIndex of
             1: begin ExpClass := TDBGridEhExportAsXLS; Ext := 'xls'; end;
             2: begin ExpClass := TDBGridEhExportAsCSV; Ext := 'csv'; end;
             3: begin ExpClass := TDBGridEhExportAsHTML; Ext := 'htm'; end;
             4: begin ExpClass := TDBGridEhExportAsRTF; Ext := 'rtf'; end;
             5: begin ExpClass := TDBGridEhExportAsText; Ext := 'txt'; end;
           else
             ExpClass := nil; Ext := '';
           end;
           if ExpClass <> nil then
           begin
             if UpperCase(Copy(lssavedialog.FileName, Length(lssavedialog.FileName) - 2, 3)) <> UpperCase(Ext) then
               lssavedialog.FileName := lssavedialog.FileName + '.' + Ext;
             if FileExists(lssavedialog.FileName) then
             begin
               if application.MessageBox('文件名已存在,是否覆盖', '提示', MB_ICONASTERISK or MB_OKCANCEL) <> idok then
               begin
                 exit;
               end;
             end;
             Screen.Cursor := crHourGlass;
             try
             SaveDBGridEhToExportFile(ExpClass, DBGridEh1, lssavedialog.FileName, true);
             except
               ShowMessage('NO');
             end;
             Screen.Cursor := crDefault;
           end;
         end;
       finally
         lssavedialog.Free;
       end;

    end;

  • 相关阅读:
    作业
    剑指Offer:链表中倒数第k个节点
    剑指Offer:反转链表
    剑指Offer:数值的整数次方
    剑指Offer:剪绳子Ⅰ和剪绳子Ⅱ
    剑指Offer:机器人的运动范围
    Linux下进程与线程的区别
    剑指Offer:调整数组顺序使奇数位于偶数前面
    剑指Offer:删除链表的节点
    剑指Offer:打印从1到最大的n位数
  • 原文地址:https://www.cnblogs.com/cnajian/p/2656958.html
Copyright © 2020-2023  润新知