2015-10-14 22 views
0

我有一個網頁形式的網格視圖,其中包含圖像調整大小爲40X40像素,但是當我導出的網格視圖出色的圖像返回到那裏原始大小如何我可以出口的網格視圖到Excel與圖像調整爲我的期望尺寸asp.net:export gridview與圖像excell

這是出口代碼我使用

Try 
GridView2.AllowPaging = False 

Response.Clear() 
Response.AddHeader("content-disposition", "attachment;filename=ComputerParts.xls") 
Response.ContentType = "application/ms-excel" 
Response.ContentEncoding = System.Text.Encoding.Unicode 
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble()) 

Dim sw As System.IO.StringWriter = New System.IO.StringWriter() 
Dim hw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw) 

txtSelectedComputer.RenderControl(hw) 
txtEmployeeName.RenderControl(hw) 
GridView2.RenderControl(hw) 

Response.Write(sw.ToString()) 
Response.End() 

GridView2.AllowPaging = True 

抓住前作爲SQLEXCEPTION Masterlbl1.Text = GeneralFuctions.interpret_error_number(ex.Number) 抓住前作爲異常 Masterlbl2。 Text =「حدثخطأغيرمتوقع。مصدرال طأ:」 & ex.Source.ToString 結束Try

回答

0

我沒有看到HTML輸出,所以我不能確定你如何在GridView控件定義圖像的寬度和高度。因此,我做了一個簡單的實驗並得到了一個有趣的結果。

我的Excel是2007年。我用記事本編寫了一個簡單的HTML頁面,其中包含一個表格。然後我把以下標記的圖像:

<img src="test.png" style="width=10px; height: 10px"> 

該圖像將在Excel中保持實際大小。

但它會與下面的標籤收縮:

<img src="test.png" width="10" height="10"> 

我認爲Excel中使用的舊fasioned HTML解析器來顯示內容。如果使用ASP.NET的Image控件,它將生成帶有style屬性的HTML。也許你會需要一些解決方法來改變輸出。我不知道你使用的是什麼版本的Excel。我希望這個結果會有所幫助。

+0

有趣的是,你是對的。但是我們如何修改導出代碼以更好地完成任務 –

+0

您可以在Image控件的Attributes屬性中添加一個條目。恩。 myImage.Attributes.Add(「width」,「10」)。最好你可以讓這個語句只在導出到Excel時執行。 – hexaium

+0

該屬性在我的webform中以正確的語法正確設置,但導出代碼以新方式自動生成,並且excel只理解舊方式 –