簡體   English   中英

如何在導出到Excel時刪除網格中的圖像

[英]How to remove images in grid while exporting to excel

我有一個包含一些數據的網格,對於一列我添加了圖像以更好地了解用戶。 現在我有一個導出選項將網格導出到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();

如果您不想顯示它,您可能會遍歷所有單元格並檢查單元格的內容是否為圖片。 if(Table.Cell(row,col).GetType().Equals("msoPicture"))然后將單元格的內容設置為null或任何您想要的值。 對於圖片,如果您仍然需要它,您可以將其保存在臨時文件中或復制到剪貼板(糟糕的實踐)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM