2014-11-22 1 views
1

웹 페이지에 표시되는 이미지를 내보내려고합니다. 이 이미지는 Sql 이미지 데이터 형식으로 저장됩니다. 이미지를 표시하는 동안 이미지를 Base64String으로 변환합니다.이미지를 Word 문서 파일에 SQL 서버에서 삽입

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

페이지를 내보내는 동안 이미지가 워드 문서 파일에 표시되지 않습니다.

보안상의 이유로 서버에 이미지를 저장할 수 없습니다. 코드 아래의 은 단어 파일로 내보내기 용입니다.

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

실제로 HTML을 단어 MIME 유형으로 렌더링하면 Word 문서가 작성되지 않습니다. 나는 단어가 데이터를 지원한다고 믿지 않는다 : 2007 년 이전의 단어 형식보다 훨씬 새로운 이미지 정의이기 때문에. 대신 OpenXML SDK를 사용해보십시오. Word 2007 이상의 문서 만 만들지 만 대부분의 사람들이 볼 수 있습니다. OpenXML SDK를 사용하면 실제 문서 doc을 만들고 이진 이미지 데이터에서 이미지를 만들 수 있습니다.

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