如何在.XLS文件中显示图像以及其他信息 [英] How To Display an Image in .XLS file along with other information

查看:86
本文介绍了如何在.XLS文件中显示图像以及其他信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我被赋予在使用.xls文件生成报告的过程中在excel工作表中显示图像的任务.

这是我的代码:

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 :

<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:



Reports.aspx.cs:

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




当我单击"lnkbtnExport"时,它将在Excel工作表中生成无图像的报告..现在,我希望在Excel工作表中显示一些.jpg图像..

有人可以帮我吗?




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?

推荐答案

拉吉,

请参见 [
Hi Raj,

See this[^]. It might be useful.


这篇关于如何在.XLS文件中显示图像以及其他信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆