Created
December 28, 2012 16:12
-
-
Save cofearabi/4399232 to your computer and use it in GitHub Desktop.
(C#) make a chart from excel data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Form1_Load(object sender, EventArgs e) | |
{ | |
// The Excel file name | |
string fileNameString = "\\temp.xls"; | |
// Create connection object by using the preceding connection string. | |
string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + | |
fileNameString + ";Extended Properties=\"Excel 8.0;HDR=YES\""; | |
OleDbConnection myConnection = new OleDbConnection( sConn ); | |
myConnection.Open(); | |
// The code to follow uses a SQL SELECT command to display the data from the worksheet. | |
// Create new OleDbCommand to return data from worksheet. | |
OleDbCommand myCommand = new OleDbCommand( "Select * From [6954$B1:D250]", myConnection ); | |
// create a database reader | |
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); | |
// Populate the chart with data in the file | |
chart1.DataBindTable(myReader, "hiduke"); | |
//chart1.Series[0].ChartType = SeriesChartType.Line; | |
chart1.Series["svalue"].ChartType = SeriesChartType.Line; | |
chart1.Series["hvalue"].ChartType = SeriesChartType.Line; | |
// close the reader and the connection | |
myReader.Close(); | |
myConnection.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment