closedxml 添加图像 vb
closedxml add image vb
我正在 ASP.NET 中做一个网络表单,目前正在使用 ClosedXML,有没有办法在工作表中的某个位置插入图像?我有这个代码
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()
更新: ClosedXML 现在支持图像,参见 here。
原回答:
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.
正如 Raidri 所说,我认为你做不到。
但我使用 Open XML 使它工作,尽管它并不完全简单:
http://polymathprogrammer.com/2009/11/30/how-to-insert-an-image-in-excel-open-xml/
我正在 ASP.NET 中做一个网络表单,目前正在使用 ClosedXML,有没有办法在工作表中的某个位置插入图像?我有这个代码
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()
更新: ClosedXML 现在支持图像,参见 here。
原回答:
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.
正如 Raidri 所说,我认为你做不到。
但我使用 Open XML 使它工作,尽管它并不完全简单:
http://polymathprogrammer.com/2009/11/30/how-to-insert-an-image-in-excel-open-xml/