Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting image to excel using asp.net (vb.net)

Status
Not open for further replies.

EricBonsu

MIS
Jul 19, 2006
17
US
I have looked everywhere and I can't figure out how to export an image to excel. I have know how to export a datagrid to excel but I'm trying to export an image as well. I would appreciate any help.

Eric
 
do you want to display the image in excel, or the bytes? to add the bytes convert the byte array to a string and insert into a cell. you would also need to include the content type so you can convert it back to an image.

to insert an image you will need to add an object (not sure what type) to hold the image and then stream the bytes into this object.

I haven't done this before, but I would assume its the same as inserting an image into a Word Document. I would research dynamically adding an image to a Word Doc in VB/C#.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for the info jmeckley, I will research some more. I would appreciate any sample code if you have any.

Eric
 
Thanks, I was hoping to get asp.net/vb.net sample code. The image I get is a dynamically created image thats not stored anywhere.
 
this shouldn't be an issue. an image is just a byte array. I would assume you could read the array into a Stream object. then embed the stream into the document.

If the examples require a file you could write the stream to a file, embed the file into the documet, and finally, delete the file as it's not longer needed.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
ASP.net programming is new to me do you think you could provide sample code. This is what I am using now but I don't get an image:
[VB]
Private Sub ExportToExcel1(ByVal sender As System.Object, ByVal e As System.EventArgs)
Response.Clear()
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition","attachment;filename=ImageChart.xls")

EnableViewState = False
Controls.Add(frm)

frm.Controls.Add(WebChartViewer1)
frm.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
End Sub
[/VB]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top