导出:
[C#] 纯文本查看 复制代码 SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "导出Excel";
saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
DialogResult dialogResult = saveFileDialog.ShowDialog(this);
if (dialogResult == DialogResult.OK)
{
DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
//gridControl1.ExportToXls(saveFileDialog.FileName, options);
gridControl1.ExportToXlsx(saveFileDialog.FileName);
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
} 打印:
[C#] 纯文本查看 复制代码 DevExpress.XtraPrinting.PrintingSystem print = new DevExpress.XtraPrinting.PrintingSystem();
DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(print);
print.Links.Add(link);
link.Component = gridControl1;//这里可以是可打印的部件
string PrintHeader = "明细表";
DevExpress.XtraPrinting.PageHeaderFooter phf = link.PageHeaderFooter as DevExpress.XtraPrinting.PageHeaderFooter;
phf.Header.Content.Clear();
phf.Header.Content.AddRange(new string[] { "", PrintHeader, "" });
phf.Header.Font = new System.Drawing.Font("宋体", 10, System.Drawing.FontStyle.Regular);
phf.Header.LineAlignment = DevExpress.XtraPrinting.BrickAlignment.Center;
link.CreateDocument(); //建立文档
print.PreviewFormEx.Show();//进行预览
我用上面的代码都只能导出或打印主表的数据,请问主从表的数据一起导出或打印,怎么做?
|