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. MySQL服务器发生OOM的案例分析

    [问题] 有一台MySQL5.6.21的服务器发生OOM,分析下来与多种因素有关 [分析过程] 1.服务器物理内存相对热点数据文件偏小,62G物理内存+8G的SWAP,数据文件大小约550G 触发OO ...

  2. odoo权限管理(二.记录管理)

    规则保存在ir.rule模型表里,需要设置关联某个模型,关联很多组,访问权限控制和domian. 通过domain_force过滤出的一些记录来执行约束. 例子:经理只能删除状态为'cancel'的客 ...

  3. iOS 11开发教程(十三)iOS11应用编辑界面添加视图

    iOS 11开发教程(十三)iOS11应用编辑界面添加视图 在iOS中添加视图的方式有两种:一种是使用编辑界面添加视图:另一种是使用代码添加视图.以下是这两个方式的详细介绍. 1.编辑界面添加视图 使 ...

  4. jQuery方法实现

    children 原生JavaScript中,如果希望找到某个元素的子元素,只能通过Node类型上的children方法一步一步获取.如 let li = document.querySelector ...

  5. react比较入门的小demo

    什么是jsx?    JSX是JavaScript  XML 这两个单词的缩写,xml和html非常类似,简单来说可以把它理解成使用各种各样的标签,大家可以自行 百度.所以jsx就是在javascri ...

  6. 15、Redis的集群

     写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------------------- ...

  7. request.getRequestDispatcher("").forward()中文乱码

    即使jsp页面的编码已设为“UTF-8”,有中文的地方还是会出现乱码,但是用response.sendRedirect不会出现此问题. 解决方案一: 不使用PrintWriter out=respon ...

  8. USBDM RS08/HCS08/HCS12/Coldfire V1,2,3,4/DSC/Kinetis Debugger and Programmer -- BDM Construction and Firmware

    Construction. Build the hardware using the information provided in the PCB download. The following a ...

  9. ISO 7816-4: Annex A: Transportation of APDU messages by T=0

    http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-4_annex-a.aspx Annex A: Transportation ...

  10. Dapper-translation 分布式监控系统

    http://bigbully.github.io/Dapper-translation/ https://github.com/bigbully/Dapper-translation