VB.Net Excel Chart Save/Export to Image

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am trying to sort out how to save or export a excel chart to a jpg image. this is what I have so far, but is obviously not working.
greatly appreciated.
<pre class="prettyprint lang-vb Private Sub ButtonJPG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonJPG.Click
Export chart as picture file
Dim MyExcel As New Excel.Application
Dim img As Image
MyExcel.Workbooks.Open("C:TEMPFileName.xls")
MyExcel.Sheets("Chart1").activate()
MyExcel.Visible = False
MyExcel.ChartObjects("Chart1").Chart.Export(FileName:="C:TempChart1.jpg", FilterName:="JPG")
Set img here to avoid exception that will be thrown if the print button is not pressed
img = Image.FromFile("C:TempChart1.jpg")
MyExcel.ActiveWorkbook.Close(SaveChanges:=False)
MyExcel.Quit()
End Sub[/code]
The error Im getting:
Public member ChartObjects on type ApplicationClass not found.

View the full article
 
Back
Top