DEV GridControl导出到Excel或打印
//方法1
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.Title = "导出Excel";
fileDialog.Filter = "Excel文件(*.xls)|*.xls";
DialogResult dialogResult = fileDialog.ShowDialog(this);
if (dialogResult == DialogResult.OK)
{
DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
gridControl1.ExportToXls(fileDialog.FileName);
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//方法2
public override void ImportExcel()
{
if (XtraMessageBox.Show("确定要将本页面数据导入到Excel内?") == DialogResult.OK)
{
try
{
if (this.DataSourceTable == null || this.DataSourceTable.Rows.Count == )
{
XtraMessageBox.Show("没有数据要导出!");
return;
}
this.SaveFileDialog.Filter = "Excel文件(*.xls)|*.xls";
if (this.SaveFileDialog.ShowDialog(this) == DialogResult.OK)
{
BaseFormFactory.ProcessFactory.Show(this, "数据导出开始");
ExportTo(new DevExpress.XtraExport.ExportXlsProvider(this.SaveFileDialog.FileName));
} }
catch (Exception vErr)
{
XtraMessageBox.Show("导出数据失败!错误源:" + vErr.Message);
}
finally
{
BaseFormFactory.ProcessFactory.Close();
XtraMessageBox.Show("导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void ExportTo(DevExpress.XtraExport.IExportProvider provider)
{
DevExpress.XtraGrid.Export.BaseExportLink link = this.gridData.gridView2.CreateExportLink(provider);
(link as DevExpress.XtraGrid.Export.GridViewExportLink).ExpandAll = false;
link.ExportTo(true);
provider.Dispose();
}
打印
PrintingSystem print = new DevExpress.XtraPrinting.PrintingSystem();
PrintableComponentLink link = new PrintableComponentLink(print);
print.Links.Add(link);
link.Component = (currentControl as GridControl);//这里可以是可打印的部件
PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;
phf.Header.Content.Clear();
phf.Header.Content.AddRange(new string[] { "", "", "" });
phf.Header.Font = new System.Drawing.Font("宋体", , System.Drawing.FontStyle.Bold);
phf.Header.LineAlignment = BrickAlignment.Center;
link.CreateDocument(); //建立文档
print.PreviewFormEx.Show();//进行预览
DEV GridControl导出到Excel或打印的更多相关文章
- DEV GridControl 导出到Excel
SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "导出Excel"; sa ...
- Dev GridControl导出
问题一. DevExpress GridView导出到Excel中不能导出自定义日期 问题描述: 我有一个第一列为日期列的GridView.它在运行时会绑定到日期,但他们通过CustomColumnD ...
- DevExpress GridControl 导出为Excel
private void btnExport_ItemClick(object sender, EventArgs e) { SaveFileDialog sa ...
- 如何将DevExpress的Gridcontrol导出到Excel
private void simpleButton1_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new S ...
- Dev GridControl数据导出格式问题
环境:DevExpress9.3,Vs2008 DevExpress的GridControl提供方便的数据导出到Excel功能,导出中用户可以根据GridControl的格式进行导出(ExportTo ...
- DevExpress GridControl GridView 导出到 Excel 类
说明: 1>GridView 导出到 Excel (如果分页,只导出当前页数据) 2>GridView 导出到 Excel 3>方法2可以参考DataTable 导出到 Excel ...
- 个人永久性免费-Excel催化剂功能第50波-批量打印、导出PDF、双面打印功能
在倡导无纸化办公的今天,是否打印是一个碍眼的功能呢,某些时候的确是,但对于数据的留存,在现在鼓吹区块链技术的今天,仍然不失它的核心价值,数据报表.单据打印出来留存,仍然是一种不可或缺的数据存档和防篡改 ...
- Qt编写数据导出到Excel及Pdf和打印数据
一.前言 用Qt开发已经九年了,期间用Qt做过不少的项目,在各种项目中有个功能很常用,尤其是涉及到数据记录存储的项目,那就是需要对查询的数据进行导出到Excel,或者导出到Pdf文件,或者直接打印查询 ...
- Winform 导出成Excel打印代码
WinForm中 直接调用Excel的打印预览功能,但不显示Excel文件 using Microsoft.Office.Interop.Excel; //引用 public void PrintPr ...
随机推荐
- <audio>使用2
1.属性测试 <!--显示控件--> <audio src="../images/wind.mp3" id="audioOne" contro ...
- O the joy of having nothing / 아무것도 갖지않고
Chords: C G Am Em F C Dm G C G Am Em F C Am Dm G English - O the joy of having nothing and being not ...
- 利用cookie改变背景色
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SqlHelper 简单版
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- SDK编程模板
#include<Windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINS ...
- mysql 命令
1.查看数据库: mysql> show databases; 2.使用数据库 mysql> use mysqldata; 3.查看数据表 mysql> show tables; 4 ...
- ado.net实现一个通知公告功能
一.建立相应的数据库,此处就不多说了,相信大家都非常了解
- 常用网站开发类Firefox扩展插件 (转)
作为一个 Web 开发人员,你几乎没有理由不喜欢Firefox,因为在Firefox下有很多专门针对开发的扩展插件,非常好用,这里就介绍一些常用的针对网站开发的FireFox扩展,供Web开发人员参考 ...
- PHP学习笔记,自己动手写个MVC的框架 -- base所有代码
<?php /** 名称:基础类 作用:引用参数处理类,加载基础配置, 作者:swordphp@126.com 创建日期:2013-07-31 **/ require_once(ROOT_PAT ...
- 转——iptables详细配置
基本原理及命令使用 http://my.oschina.net/hevakelcj/blog/313212 基础知识 Linux系统内核内建了netfilter防火墙机制.Netfilter(数据包 ...