• 导出/导入Tdbgrideh数据


    {*******************************************************}
    {                                                       }
    {       导出Tdbgrideh数据                               }
    {                                                       }
    {       版权所有 (C) 2007 咏南工作室                    }
    {                                                       }
    {*******************************************************}

    unit uExport;

    interface

    uses
      DBGridEhImpExp, DBGridEh, SysUtils, Dialogs, ComObj, ActiveX, Variants, db,
      FormWait;

    procedure ExpDbgridEh(grid:TDBGridEh);
    procedure ImpDbgridEH(Grid:TDBGridEh);

    implementation

    //==============================================================================
    // 增加进度条显示 by cxg 2008-01-05 10:08:09
    //==============================================================================

    procedure ImpDbgridEH(Grid:TDBGridEh);
    var
      OpenDialog:TOpenDialog;
    begin
      if (not Assigned(grid)) or (not grid.DataSource.DataSet.Active) then
        exit;
      OpenDialog:=TOpenDialog.create(nil);
      try
        OpenDialog.Filter:='*.HTM|文本文件'
        OpenDialog.FilterIndex:=1;
        if OpenDialog.Execute then
        begin
          ShowWaitText('请稍候');
          LoadDBGridEhFromImportFile(TDBGridEhImportAsText,
            Grid,OpenDialog.FileName,True);
        end; 
      finally
        OpenDialog.Free;
        ShowWaitText();
      end;  
    end; 

    procedure ExpDbgridEh(grid:TDBGridEh);
    var
      ExpClass:TDBGridEhExportClass;
      Ext:String;
      SaveDialog:TSaveDialog;
    begin
      if (not Assigned(grid)) or (not grid.DataSource.DataSet.Active)
        or (grid.DataSource.DataSet.IsEmpty) then exit;
      SaveDialog:=TSaveDialog.Create(nil);
      try
        SaveDialog.FileName := 'file1';
        SaveDialog.Filter:='EXCEL电子表格|*.XLS|HTML网页|*.HTM|文本文件|*.TXT|CSV'
          +'|*.CSV|RTF富文本|*.RTF';
        SaveDialog.FilterIndex:=1;
        if SaveDialog.Execute then
        begin
          ShowWaitText('请稍候');  
          try
            case SaveDialog.FilterIndex of
              1: begin ExpClass := TDBGridEhExportAsXLS; Ext := 'xls'; end;
              2: begin ExpClass := TDBGridEhExportAsHTML; Ext := 'htm'; end;
              3: begin ExpClass := TDBGridEhExportAsText; Ext := 'txt'; end;
              4: begin ExpClass := TDBGridEhExportAsCSV; Ext := 'csv'; end;
              5: begin ExpClass := TDBGridEhExportAsRTF; Ext := 'rtf'; end;
            else
              ExpClass := nil; Ext := '';
            end;
            if ExpClass <> nil then
            begin
              if UpperCase(Copy(SaveDialog.FileName,
                Length(SaveDialog.FileName)-2,3))<> UpperCase(Ext) then
                SaveDialog.FileName := SaveDialog.FileName + '.' + Ext;
              SaveDBGridEhToExportFile(ExpClass,grid,SaveDialog.FileName,true);
            end;
          finally
            ShowWaitText();
          end;
        end;
      finally
        FreeAndNil(SaveDialog);
      end; 
    end;

    end.

  • 相关阅读:
    sc输入输出
    sc基本语法
    sp启动执行
    sp的配置安装
    软件质量属性的代码层实现
    以淘宝网为例描述常见质量属性场景
    架构漫谈读后感
    《架构之美》阅读笔记三
    《架构之美》阅读笔记二
    大三寒假学习进度笔记Day25
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940900.html
Copyright © 2020-2023  润新知