0

我有一个包含一些数据的网格,对于一列,我添加了图像以更好地向用户展示。现在我有一个导出选项,可以将网格导出到 excel 表。在 excel 中我得到图像未找到图标。我不想在 Excel 表中向用户显示图像。任何帮助

Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "123.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
// gdAclog.AllowPaging = false;
// gdAclog.DataBind();
//Change the Header Row back to white color
gdAclog.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gdAclog.HeaderRow.Cells.Count; i++)
{
    gdAclog.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in gdAclog.Rows)
{
    gvrow.BackColor = Color.White;
    if (j <= gdAclog.Rows.Count)
    {
        if (j % 2 != 0)
        {
            for (int k = 0; k < gvrow.Cells.Count; k++)
            {
                gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
            }
        }
    }
    j++;
}
gdAclog.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
4

1 回答 1

2

如果您不想显示它,您可能会遍历所有单元格并检查单元格的内容是否是图片。if(Table.Cell(row,col).GetType().Equals("msoPicture"))然后将单元格的内容设置为 null 或您想要的任何值。对于图片,如果您仍然需要它,您可以将其保存在临时文件中或复制到剪贴板(不好的做法)。

于 2013-05-15T13:48:05.127 回答