繁体   English   中英

如何将AjaxToolkit控件折线图导出到Excel

[英]How to export AjaxToolkit control linechart to Excel

在应用程序中,我具有网格视图和Ajax Toolkit控件折线图,我需要将网格视图和折线图导出到excel工作表(开放式办公室/天秤座办公室)。 我在导出按钮中尝试了一些代码,但发生的情况是导出了网格视图,但折线图未导出到Excel。 我的页面看起来像这样[我的图表图像]
通过单击导出按钮,然后只有网格视图将导出到excel,但不会将其折线图导出到excel。我需要的是将图表导出到excel。 这个怎么做

我试过的代码是:
.aspx:

 <cc1:LineChart ID="LineChart1" runat="server" ChartHeight="300"  ChartWidth="900" ChartType="Basic" ChartTitleColor="#0E426C" Visible="true" CategoryAxisLineColor="#D08AD9" ValueAxisLineColor="#D08AD9" BaseLineColor="#A156AB"></cc1:LineChart>

.cs:

 protected void btnExport_Click(object sender, EventArgs e)
    {

        Response.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "filename.xls"));
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw); 
        base.OnPreRender(e);
        ScriptManager sm = ScriptManager.GetCurrent(Page);
        sm.RegisterScriptControl(LineChart1);
        LineChart1.Visible = true;          
       for (int i = 0; i < grdview1.HeaderRow.Cells.Count; i++)
        {
           grdview1.HeaderRow.Cells[i];
        }
        grdview1.RenderControl(htw);
        LineChart1.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();        
    }

public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }

我添加了OnPreRender()来注册scriptmanager控件

    protected override void OnPreRender(EventArgs e)
    {
        /* Verifies that the control is rendered */
        base.OnPreRender(e);
        ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

        if (scriptManager == null)
        {

            scriptManager = new ScriptManager();

            scriptManager.ID = "ScriptManager1";

            scriptManager.EnablePartialRendering = true;

            Controls.AddAt(0, scriptManager);

        }
    }

任何人都可以帮我导出出口图。

谢谢

不,您不能导出LineChart。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM