• 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();

    这样就可以把表格还有图表一起导出来了~

    年轻过得闲,以后被人嫌... 年轻累不死....
  • 相关阅读:
    由吃饺子想到的多线程情况下的数据共享问题
    关于伪静态的几个体会
    最近改造的一款可多选的日历插件,已通过兼容性测试
    对kingthy创作的Vtemplate模板引擎的使用心得
    从前辈们整理的数据库优化经验中得到的一点心得分享
    关于近期对Lucene.Net应用研究学习的总结
    对SharpICTCLAS 1.0的一点小小的修改记录
    转 Blob、DataURL、canvas、image的相互转换
    节日_100
    模板生成_100
  • 原文地址:https://www.cnblogs.com/hrx-star/p/3257579.html
Copyright © 2020-2023  润新知