zoukankan      html  css  js  c++  java
  • (转载)DBGridEh导出Excel等格式文件

    DBGridEh导出Excel等格式文件

    uses DBGridEhImpExp;
    {-------------------------------------------------------------------------------
    过程名: TfrmEmplyExport.OutToFile
    作者: han
    日期: 2007.08.08
    参数: IADO : TADOQuery; DgEh : TDBGridEh
    返回值: 无
    说明: 导出查询结果到文件
    -------------------------------------------------------------------------------}
    procedure TfrmEmplyExport.OutToFile(IADO : TADOQuery; DgEh : TDBGridEh);
    var
    ExpClass:TDBGridEhExportclass;
    Ext:String;
    FSaveDialog: TSaveDialog;
    begin
    try
    if not IADO.IsEmpty then
    begin
    FSaveDialog := TSaveDialog.Create(Self);
    FSaveDialog.Filter:='Excel 文档 (*.xls)|*.XLS|Text files (*.txt)|*.TXT|Comma separated values (*.csv)|*.CSV|HTML file (*.htm)|*.HTM|Word 文档 (*.rtf)|*.RTF';
    if FSaveDialog.Execute and (trim(FSaveDialog.FileName)<>'') then
    begin
    case FSaveDialog.FilterIndex of
    1: begin ExpClass := TDBGridEhExportAsXLS; Ext := 'xls'; end;
    2: begin ExpClass := TDBGridEhExportAsText; Ext := 'txt'; end;
    3: begin ExpClass := TDBGridEhExportAsCSV; Ext := 'csv'; end;
    4: begin ExpClass := TDBGridEhExportAsHTML; Ext := 'htm'; end;
    5: begin ExpClass := TDBGridEhExportAsRTF; Ext := 'rtf'; end;
    end;
    if ExpClass <> nil then
    begin
    if UpperCase(Copy(FSaveDialog.FileName,Length(FSaveDialog.FileName)-2,3)) <> UpperCase(Ext) then
    FSaveDialog.FileName := FSaveDialog.FileName + '.' + Ext;
    if FileExists(FSaveDialog.FileName) then
    begin
    if application.MessageBox('文件名已存在,是否覆盖 ', '提示', MB_ICONASTERISK or MB_OKCANCEL)<>idok then
    exit;
    end;
    Screen.Cursor := crHourGlass;
    SaveDBGridEhToExportFile(ExpClass,DgEh,FSaveDialog.FileName,true);
    Screen.Cursor := crDefault;
    MessageBox(Handle, '导出成功 ', '提示', MB_OK +
    MB_ICONINFORMATION);
    end;
    end;
    FSaveDialog.Destroy;
    end;
    except
    on e: exception do
    begin
    Application.MessageBox(PChar(e.message), '错误', MB_OK + MB_ICONSTOP);
    end;
    end;
    end;

  • 相关阅读:
    web前端的发展态势
    AngularJs 简单入门
    css代码优化篇
    git提交报错:Please make sure you have the correct access rights and the repository exists.
    Activiti工作流框架学习
    遍历map集合的4种方法
    js设置日期、月份增加减少
    Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
    webservice_rest接口_学习笔记
    相互匹配两个list集合+动态匹配${}参数
  • 原文地址:https://www.cnblogs.com/angelbd/p/3373058.html
Copyright © 2011-2022 走看看