简体   繁体   中英

closedxml add image vb

i am doing a webform in ASP.NET and currently working with ClosedXML,is there a way to insert an image inside a worksheet in a position?, i have this code

Dim wb As New XLWorkbook()
Dim ws As IXLWorksheet = wb.Worksheets.Add("NAME")
Dim httpResponse = Response
httpResponse.Clear()
httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

'INSERT IMAGE HERE'
ws.insertimage("imagepath")'???

Dim namedoc As String = "namedoc"
httpResponse.AddHeader("content-disposition", "attachment;filename=""" + namedoc+ ".xlsx""")
Using tmpMemoryStream As MemoryStream = New MemoryStream()
    wb.SaveAs(tmpMemoryStream)
    tmpMemoryStream.WriteTo(httpResponse.OutputStream)
    tmpMemoryStream.Close()
End Using
httpResponse.End()

Update: ClosedXML now supports images, see here .


Original answer:

How can I insert an image?

You can't. Although you can open an Excel that already has an image and save it preserving the image, you can't insert a new image with ClosedXML.

from the official FAQ

As Raidri says, I don't think you can.

But I got it working using Open XML using this, although it's not exactly straightforward:
http://polymathprogrammer.com/2009/11/30/how-to-insert-an-image-in-excel-open-xml/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM