简体   繁体   中英

How to export AjaxToolkit control linechart to Excel

In application i have grid view and Ajax Toolkit control linechart i need to export grid view and linechart to excel sheet(open office/Libra office). i tried some code in export button but what happens grid view is exported but line chart is not export to excel. my page appear like this [my chart image]
by clicking the export button then only grid view will export to excel but not linechart it will not export.what i need is chart should be export to excel. how to do this

i tried code is:
.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 */
    }

I added OnPreRender() for Registering the scriptmanager control

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

        }
    }

Can anyone help me out how can i export linechart.

Thank you

不,您不能导出LineChart。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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