excel chart in VB.NET

P

Prasun

Code:

Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
oWB = oXL.Workbooks.Open("C:\data.xls") '---> Exception thrown here
'Dim ThisWorkbook As Excel.Workbook
Dim ThisWorksheet As Excel.Worksheet
ThisWorksheet = oWB.ActiveSheet

Dim charts As Excel.ChartObjects = _
CType(ThisWorksheet.ChartObjects(), Excel.ChartObjects)

' Adds a chart at x = 100, y = 300, 500 points wide and 300 tall.
Dim chartObj As Excel.ChartObject = charts.Add(100, 300, 500, 300)
Dim chart As Excel.Chart = chartObj.Chart

' Gets the cells that define the bounds of the data to be charted.
Dim chartRange As Excel.Range = ThisWorksheet.Range("A2", "B8")
chart.SetSourceData(chartRange)

chart.ChartType = Excel.XlChartType.xlXYScatter
Dim series As Excel.Series
Dim seriesCollection As Excel.SeriesCollection = _
CType(chart.SeriesCollection(), Excel.SeriesCollection)
series = seriesCollection.Item(seriesCollection.Count)
End Sub




I have the following exception thrown in the line shown above.


An unhandled exception of type 'System.NullReferenceException' occurred in
ChartDisplay.exe

Additional information: Object reference not set to an instance of an
object.


does anyone know what is wrong
 
D

davesauny

More than likely c:\Data.xls doesn't exist! when using IO you should
always prepare for nullexception errors with try...catch blocks for
anything that may occur which you are not prepared for.

Dave
 
D

davesauny

More than likely c:\Data.xls doesn't exist! when using IO you should
always prepare for nullexception errors with try...catch blocks for
anything that may occur which you are not prepared for.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top