2014-11-22 64 views
1

我想導出顯示在網頁上的圖像。該圖像存儲在Sql圖像數據類型中。顯示圖像時,我將圖像轉換爲Base64String。從SQL Server插入圖像到Word Doc文件

Image1.ImageUrl = "data:image/jpg;base64," & Convert.ToBase64String(imgPhoto)  

導出頁面時,圖像不顯示在word文檔文件中。

由於安全原因,我無法將圖像存儲在服務器上。以下代碼的 用於導出爲word文件。

Response.AddHeader("content-disposition", "attachment;filename=Test.doc") 
    Response.Cache.SetCacheability(HttpCacheability.NoCache) 
    Response.ContentType = "application/ms-word " 
    Response.Charset = "" 
    Dim stringWrite As New System.IO.StringWriter() 
    Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite) 

    ' Create a form to contain the grid 
    ControlID.RenderControl(htmlWrite) 

    Dim stringWrite1 As New System.IO.StringWriter() 
    Dim htmlWrite1 As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite1) 

    ' Create a form to contain the grid 
    ImageLogo.RenderControl(htmlWrite1) 

    Response.Write(stringWrite1.ToString() & stringWrite.ToString()) 
    Response.[End]()  

回答

0

您確實沒有創建Word文檔,只是將HTML呈現爲單詞MIME類型。我不認爲單詞支持數據:圖像定義,因爲它比2007年以前的單詞格式要新。相反,請嘗試OpenXML SDK。雖然它只創建Word 2007+文檔,但大多數人都可以查看它們。 OpenXML SDK將使您能夠創建真實的文檔文檔並從二進制圖像數據創建圖像。

http://www.microsoft.com/en-us/download/details.aspx?id=30425

http://msdn.microsoft.com/en-us/library/office/bb448854%28v=office.15%29.aspx