C# DevExpress GridControl导出表格【转】

DevExpress的GridControl提供方便的数据导出功能,可以方便的导出Exce,PDF,Html页面,world形式,无需写额外的代码,方便、快捷。

/// <summary>
        /// 导出表格 /// </summary> /// <param name="gridControl1"></param> public static void DevExpressGridControlExport(GridControl gridControl1) { using (var saveDialog = new SaveFileDialog()) { saveDialog.Filter = Resources.CommonFunction_DevExpressGridControlExport_Excel_97_2007文件___xls_Excel_2010___xlsx_Excel__2003___xls____xls_Excel__2010____xlsx____xlsx__RichText_File___rtf____rtf__Pdf_File___pdf____pdf__Html_File___html____html; if (saveDialog.ShowDialog() == DialogResult.Cancel) return; var exportFilePath = saveDialog.FileName; var fileExtenstion = new FileInfo(exportFilePath).Extension; switch (fileExtenstion) { case ".xls": gridControl1.ExportToXls(exportFilePath); break; case ".xlsx": gridControl1.ExportToXlsx(exportFilePath); break; case ".rtf": gridControl1.ExportToRtf(exportFilePath); break; case ".pdf": gridControl1.ExportToPdf(exportFilePath); break; case ".html": gridControl1.ExportToHtml(exportFilePath); break; case ".mht": gridControl1.ExportToMht(exportFilePath); break; } if (File.Exists(exportFilePath)) { try { if (DialogResult.Yes == MessageBox.Show(Resources.CommonFunction_DevExpressGridControlExport_, Resources.CommonFunction_DevExpressGridControlExport_提示, MessageBoxButtons.YesNo)) { Process.Start(exportFilePath); } } catch { var msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath; MessageBox.Show(msg, Resources.CommonFunction_DevExpressGridControlExport_Error_, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { var msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath; MessageBox.Show(msg, Resources.CommonFunction_DevExpressGridControlExport_Error_, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
原文网址: https://blog.csdn.net/Gary_888/article/details/70212796
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值