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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel chart

Status
Not open for further replies.

fmardani

Programmer
Jul 24, 2003
152
0
0
does anyone know of a good link or an example to learn on how to create a chart in excel(using the values in the cells of a sheet) using vb.net ?
Thanks
 
Take a look to the following:

'Set the culture information for the current thread to English before instantiating Excel.Without this line of code nothing works. It's a bug of MS
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US") 'or "fr-FR" or ..., this depends on your Excel version

' Start Excel and get Application object.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True

' Get a workbook.
Dim wbk As Object
wbk = oExcel.Workbooks.Open(Filename:="E:\Documents and Settings\Fotini\Desktop\MyFile.xls", UpdateLinks:=False, ReadOnly:=False)

Dim oSheet As Excel.Worksheet
oSheet = wbk.ActiveSheet

' Add a Chart for the selected data.
Dim oResizeRange As Excel.Range
oResizeRange = oSheet.Range("B7:B22").Resize(ColumnSize:=2)

Dim oChart As Excel.Chart
oChart = oSheet.Parent.Charts.Add
Dim oSeries As Excel.Series

With oChart
.ChartWizard(oResizeRange, Excel.XlChartType.xlLine, , Excel.XlRowCol.xlColumns, , , , "Chart Title", "Axis X title", "Axis Y title")
oSeries = .SeriesCollection(2)
oSeries.XValues = oSheet.Range("A7", "A22")
.SeriesCollection(1).Name = "Voie 24%"
.SeriesCollection(2).Name = "Voie 25%"
.Location(Excel.XlChartLocation.xlLocationAsObject, oSheet.Name)
End With

' Free any references.

oChart = Nothing
oResizeRange = Nothing
oSheet = Nothing
wbk = Nothing

End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top