///
/// 打印 需要引用
using DevExpress.XtraPrinting; using DevExpress.XtraPrintingLinks;
///
///
///
private
void
barbtnPrint_ItemClick(
object
sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
PrintingSystem print =
new
DevExpress.XtraPrinting.PrintingSystem();
PrintableComponentLink link =
new
PrintableComponentLink(print);
print.Links.Add(link);
link.Component = grd_newmembersummary;
//这里可以是可打印的部件
string
_PrintHeader =
"新增会员统计"
;
PageHeaderFooter phf = link.PageHeaderFooter
as
PageHeaderFooter;
phf.Header.Content.Clear();
phf.Header.Content.AddRange(
new
string
[] {
""
, _PrintHeader,
""
});
phf.Header.Font =
new
System.Drawing.Font(
"宋体"
, 14, System.Drawing.FontStyle.Bold);
phf.Header.LineAlignment = BrickAlignment.Center;
link.CreateDocument();
//建立文档
print.PreviewFormEx.Show();
//进行预览
}
///
/// 导出
///
///
///
private
void
barbtnExport_ItemClick(
object
sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
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();
grd_newmembersummary.ExportToXls(fileDialog.FileName);
DevExpress.XtraEditors.XtraMessageBox.Show(
"导出成功!"
,
"提示"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}