zoukankan      html  css  js  c++  java
  • 导出.txt / .pdf / .xls

    public static string TxtFilter = "文本文件(.txt)|*.txt";
            public static string PDFFilter = "PDF文件(.pdf)|*pdf";
            public static string XLSFilter = "Excel文件(.xls)|*.xls";
            public void ExportGrid(GridControl grid, string ext, string Filter,string title)
            {
                using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
                {
                    saveFileDialog1.FileName = "";
                    saveFileDialog1.Filter = Filter;
                    saveFileDialog1.FileName = title;
                    saveFileDialog1.OverwritePrompt = false; //已存在文件是否覆盖提示
                    if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                        return;
                    //已存在文件是否覆盖提示
                    while (System.IO.File.Exists(saveFileDialog1.FileName) &&
                        DevExpress.XtraEditors.XtraMessageBox.Show("该文件名已存在,是否覆盖?",
                        "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                    {
                        if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                            return;
                    }
                    if (saveFileDialog1.FileName != "")
                    {
                        try
                        {
                            System.IO.FileStream fs =
                               (System.IO.FileStream)saveFileDialog1.OpenFile();
                            if (ext == "txt")
                            {
                                grid.ExportToText(fs);
                            }
                            else if (ext == "pdf")
                            {
                                grid.ExportToPdf(fs);
                            }
                            else if (ext == "xls")
                            {
                                XlsExportOptions options = new XlsExportOptions();
                                options.TextExportMode = TextExportMode.Text;
                                grid.ExportToXls(fs, options);
                            }
                            //this.gcISSUESUBs.ExportToText(fs);
                            fs.Close();
                            //DevExpress.XtraEditors.XtraMessageBox.Show("数据导出成功!", "提示");
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.Contains("正由另一进程使用"))
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show("数据导出失败!文件正由另一个程序占用!", "提示");
                            }
                            else
                                DevExpress.XtraEditors.XtraMessageBox.Show("数据导出失败!数据量过大,请分别统计再导出!", "提示");
                        }
                    }
                }
            }
  • 相关阅读:
    sizeof与strlen的区别
    面试题46:求1+2+...+n
    opennebula 安装指定参数
    opennebula 开发记录
    virsh 查看hypervisor特性
    opennebula kvm日志
    Cgroup
    opennebula kvm 创建VM oned报错日志
    opennebula kvm 创建虚拟机错误
    golang hello
  • 原文地址:https://www.cnblogs.com/mapstar/p/10818090.html
Copyright © 2011-2022 走看看