zoukankan      html  css  js  c++  java
  • 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();

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

    年轻过得闲,以后被人嫌... 年轻累不死....
  • 相关阅读:
    Men and women can't be 'just friends
    thin-provisioning-tools
    自签名证书
    sqlite manager
    python -m SimpleHTTPServer 80801
    rsa or dsa?
    sl4a
    mtp
    sl4a
    基站记录仪是个啥?
  • 原文地址:https://www.cnblogs.com/hrx-star/p/3257579.html
Copyright © 2011-2022 走看看