2013-05-15 47 views
0

我有一個網格,其中包含一些數據,對於一列,我添加了圖像以提高用戶的可見度。現在我有一個導出選項將網格導出爲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(); 
+0

哪個單元格是你的圖片? –

+0

5項目模板圖像 – charan

回答

2

如果你反正不想表現出來,你可能會通過你所有的細胞中循環,並檢查單元格的內容是一張圖片。 if(Table.Cell(row,col).GetType().Equals("msoPicture"))然後您將單元格的內容設置爲空或您想要的任何值。對於圖片,如果您仍然需要它,您可以將其保存在臨時文件中或複製到剪貼板(不合格)。

相關問題