System.Windows.Forms.OpenFileDialog oFileDialog = new System.Windows.Forms.OpenFileDialog();
oFileDialog.Filter = "Excel (*.xls;*.xlsx;*)|*.xls;*.xlsx;*";
oFileDialog.ShowDialog();
string strpath = oFileDialog.FileName;
//string strpath = @"C:\Users\shihafathw\Desktop\Employees.xls";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + strpath + "';Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34 + "");
OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
DataTable dt = new DataTable();
da.Fill(dt);
oFileDialog.Filter = "Excel (*.xls;*.xlsx;*)|*.xls;*.xlsx;*";
oFileDialog.ShowDialog();
string strpath = oFileDialog.FileName;
//string strpath = @"C:\Users\shihafathw\Desktop\Employees.xls";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + strpath + "';Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34 + "");
OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
DataTable dt = new DataTable();
da.Fill(dt);
More about....C# Excel automation
ReplyDeleteLing