Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Dear All,

I am given the task to display an image in the excel sheet during generating the report with .xls file.

Here's my code :

XML
<asp:LinkButton ID="lnkbtnExport" runat="server" onclick="lnkbtnExport_Click" Visible="false" >
                    <asp:Image ImageUrl="~/Images/excel_icon.gif" ID="downloadExcel" runat="server" />
                    <asp:Label ID="lblExportExcel" Text="Export To Excel" runat="server" ></asp:Label>
                    </asp:LinkButton>


Reports.aspx.cs:

XML
protected void lnkbtnExport_Click(object sender, EventArgs e)
    {
        string Output = lblOutput.Text.ToString();
        string fileName = "attachment;filename= DashBoardReportOn_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") +  ".xls";
        Response.Clear();
        Response.AddHeader("content-disposition", fileName);
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/excel";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        //Table1.RenderControl(htmlWrite);
        DisplayTbH.RenderControl(htmlWrite);
        DisplayTb.RenderControl(htmlWrite);

        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        Table1.RenderControl(htw);
        string NewOutput = stringWrite.ToString();
        NewOutput = NewOutput.Replace("</table>", "");
        NewOutput = NewOutput + Output + "</table>";
        Response.Write(NewOutput);
        Response.Write("</head>");
        Response.Write(sw.ToString());
        Response.End();
}



When I click on "lnkbtnExport",it will generate the report in excel sheet with no image.. Now, I want some .jpg image to be displayed in excel sheet..

Can anyone please help me in this?
Posted
Comments
TweakBird 4-Feb-11 6:42am    
Re-Post! You already asked same question, http://www.codeproject.com/Questions/153731/Displaying-Image-in-Excel-Sheet.aspx. Please be patient.
Raj.rcr 5-Feb-11 6:52am    
You said be patient and I accepted ur words. But till now I have got no suggestion from any one for my problem..
Henry Minute 6-Feb-11 15:06pm    
Shhhh. (Don't tell any one I told you this but if you are getting no answers edit your question just a tiny bit and it will move up the list.) Shhhhh.

Asking the same question twice is considered rude. Doing what I suggested above too frequently or more than twice is also naughty. :)

1 solution

Hi Raj,

See this[^]. It might be useful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900