Home > Back-end >  Every all curves in how to implement the chart reading excel at different positions in the table urg
Every all curves in how to implement the chart reading excel at different positions in the table urg

Time:09-16

Now code as described below, under the time column and this column I want to read the second curve starting line 5 how to set the great god


Private void button1_Click (object sender, EventArgs e)
{
OpenFileDialog fileDialog=new OpenFileDialog ();
FileDialog. Multiselect=true;
FileDialog. Title="select file";
XLS fileDialog. Filter="all files (* *) | *. XLS *";//set to choose the type of the file
If (fileDialog ShowDialog ()==DialogResult. OK)
{
The string file=fileDialog. FileName;//returns the full path to the file
}
Chart1. The DataSource=dt;
Chart1. DataBind ();
String a, b;
DataSet1=ExcelToDataSet (fileDialog. FileName);//read selected file

Foreach (DataRow Dr In dataSet1. Tables [0]. Rows)
{
A=Dr [r]. "time" the ToString ();
B=Dr [r]. "the" ToString ();
If (a=="")
{
break;
}
If (b=="")
{
break;
}
Chart1. Series [0]. Points. AddXY (Convert. ToString (a), the Convert. ToString (b));
Chart1. Series [1]. Points. AddXY (Convert. ToString (a), the Convert. ToString (b));
}
}

The static public DataSet ExcelToDataSet (string filename)
{
The DataSet ds;
String strCon="Provider=Microsoft. Jet. The OLEDB. 4.0;" +
"Extended Properties=8.0 Excel;" +
"Data source=" + filename;
OleDbConnection myConn=new OleDbConnection (strCon);
String strCom="SELECT * FROM [engineering data table $A3: J1000]".
MyConn. The Open ();
OleDbDataAdapter myCommand=new OleDbDataAdapter (strCom myConn);

Ds=new DataSet ();
MyCommand. The Fill (ds);
MyConn. Close ();
Return the ds;
}
  • Related