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

C# DevExpress GridControl导出表格【转】的更多相关文章

  1. DevExpress GridControl导出ExportToXls 数字类型显示成货币格式

    用Dev开发很习惯直接用自带控件导出Excel,现在很少使用原生的Excel API去操作了.除非需要详细的控制. 但别人家封装好的就得按人家的规则的.在使用GridControl导出Excel时发现 ...

  2. DevExpress GridControl 导出为Excel

    private void btnExport_ItemClick(object sender, EventArgs e)         {             SaveFileDialog sa ...

  3. devexpress 数据导入(gridcontrol 导出 csv)

    // 1.gridcontrol 导出 csv: DataTable dtbNew = new DataTable(); dtbNew.Columns.Add().GetType()); dtbNew ...

  4. Dev GridControl导出

    问题一. DevExpress GridView导出到Excel中不能导出自定义日期 问题描述: 我有一个第一列为日期列的GridView.它在运行时会绑定到日期,但他们通过CustomColumnD ...

  5. DevExpress GridControl 使用方法技巧 总结 收录整理

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 ().gridView.AddNe ...

  6. DevExpress GridControl使用(转)

    DevExpress GridControl使用 (一)原汁原味的表格展示 Dev控件中的表格控件GridControl控件非常强大.不过,一些细枝末节的地方有时候用起来不好找挺讨厌的.使用过程中,多 ...

  7. Devexpress GridControl z

    http://minmin86121.blog.163.com/blog/static/4968115720144194923578/ 1 AllowNullInput=False; --Devexp ...

  8. DevExpress GridControl如何取消默认的显示方式

    DevExpress GridControl如何取消默认的显示方式,就是表格中好像还嵌套了一个表格,下面有个折叠‘+’按钮,我需要显示的是就是单表格的样式效果. 默认的样式如图: 我需要显示的效果图: ...

  9. C# DevExpress GridControl使用方法

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 ().gridView.AddNe ...

随机推荐

  1. handlebars.min.js的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. IE9中ajax请求成功后返回值却是undefined

    ie9中ajax请求一般处理程序成功后返回值始终是undefined,在网上找过很多资料,大致意思都是说前后端编码不一致造成的,但是按照资料上的方案去修改却发现根本不能解决我的问题,试过好多种方案都不 ...

  3. BZOJ1171 : 大sz的游戏

    f[i]=min(f[j])+1,线段j与线段i有交,且l[i]-l[j]<=L. 线段j与线段i有交等价于y[j]>=x[i],x[j]<=y[i]. 因为l[i]递增,所以可以维 ...

  4. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题

    C. Table Tennis Game 2 题目连接: http://codeforces.com/contest/765/problem/C Description Misha and Vanya ...

  5. PHP PSR 代码规范基本介绍

    PSR 是 PHP Standard Recommendation 的简写,即PHP推荐标准. 目前通过的规范有 PSR-0(Autoloading Standard).PSR-1(Basic Cod ...

  6. CentOS启动OpenVPN报错:Failed to start OpenVPN Robust And Highly Flexible Tunneling Application On server.

    tailf /var/log/openvpn.log 查看日志,里面有最详细的错误解说. 参考: https://forums.openvpn.net/viewtopic.php?t=21561

  7. CentOS下GPT分区(转)

    GPT格式的分区理论上是支持18EB,而MBR只支持2TB,以后大硬盘GPT是趋势.fdisk最大只能建立2TB大小的分区,创建一个大于2TB的分区就必须使用parted,parted向后兼容MBR. ...

  8. 一种高效的序列化方式——MessagePack

    最近在弄一些数据分析方面的内容,发现很多时候数据瓶颈在模块之间的数据序列化和反序列化上了,原来项目中用的是Json,找了一圈发现Json.net在Json序列化库中已经是性能的佼佼者了,便准备从序列化 ...

  9. ARM DEBUGGER FOR NEARLY ONE DOLLAR

    http://hackaday.com/2014/01/23/arm-debugger-for-nearly-one-dollar/ Oh that title is so misleading. B ...

  10. LPC-LINK 2

    LPC-Link 2 is an extensible, stand-alone debug adapter that can be configured to support various dev ...