dev....把pivotgridview和chart一起导出
首先~:
命名空间:
using DevExpress.XtraPrinting;
using DevExpress.XtraCharts.Native;
using DevExpress.XtraPrintingLinks;
using System.IO;
导出PDF:
写在,比如说是btn事件里的
PrintingSystem ps = new PrintingSystem(); PrintableComponentLink link1 = new PrintableComponentLink(); link1.Component = Exporter; link1.PrintingSystem = ps; PrintableComponentLink link2 = new PrintableComponentLink(); WebChart.DataBind(); link2.Component = ((IChartContainer)WebChart).Chart; link2.PrintingSystem = ps; CompositeLink compositeLink = new CompositeLink(); compositeLink.Links.AddRange(new object[] { link1, link2 }); compositeLink.PrintingSystem = ps; compositeLink.CreateDocument(); compositeLink.PrintingSystem.ExportOptions.Pdf.DocumentOptions.Author = "Test"; using (MemoryStream stream = new MemoryStream()) { compositeLink.PrintingSystem.ExportToPdf(stream); Response.Clear(); Response.Buffer = false; Response.AppendHeader("Content-Type", "application/pdf"); Response.AppendHeader("Content-Transfer-Encoding", "binary"); Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf"); Response.BinaryWrite(stream.GetBuffer()); Response.End(); } ps.Dispose();
导出XLS(excel)
PrintingSystem ps = new PrintingSystem(); PrintableComponentLink link1 = new PrintableComponentLink(); link1.Component = Exporter; link1.PrintingSystem = ps; PrintableComponentLink link2 = new PrintableComponentLink(); WebChart.DataBind(); link2.Component = ((IChartContainer)WebChart).Chart; link2.PrintingSystem = ps; CompositeLink compositeLink = new CompositeLink(); compositeLink.Links.AddRange(new object[] { link1, link2 }); compositeLink.PrintingSystem = ps; compositeLink.CreateDocument(); //compositeLink.PrintingSystem.ExportOptions.Xls.DocumentOptions.Author = "Test"; using (MemoryStream stream = new MemoryStream()) { compositeLink.PrintingSystem.ExportToXls(stream); Response.Clear(); Response.Buffer = false; Response.AppendHeader("Content-Type", "application/xls"); Response.AppendHeader("Content-Transfer-Encoding", "binary"); Response.AppendHeader("Content-Disposition", "attachment; filename=test.xls"); Response.BinaryWrite(stream.GetBuffer()); Response.End(); } ps.Dispose();
这样就可以把表格还有图表一起导出来了~
年轻过得闲,以后被人嫌...
年轻累不死....