当前位置:
首页 >
导出.txt / .pdf / .xls
发布时间:2025/3/16
33
豆豆
生活随笔
收集整理的这篇文章主要介绍了
导出.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("数据导出失败!文件正由另一个程序占用!", "提示");}elseDevExpress.XtraEditors.XtraMessageBox.Show("数据导出失败!数据量过大,请分别统计再导出!", "提示");}}}}
转载于:https://www.cnblogs.com/mapstar/p/10818090.html
总结
以上是生活随笔为你收集整理的导出.txt / .pdf / .xls的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 刚出道的黑客搞瘫美国输油管道!他们还边搞
- 下一篇: EF中 GroupJoin 与 Join