日期:2014-05-17 浏览次数:20761 次
private void button1_Click(object sender, EventArgs e)
{
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + "D:\\test.xls" + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [Sheet1$]", conn);
odda.Fill(dt);
dataGridView1.DataSource = dt;
}
private void ssex()
{
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel files(*.xls)|*.xls";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
FileInfo fileInfo = new FileInfo(openFileDialog.FileName);
string filePath = fileInfo.FullName;
//string connExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "d:\\test.xsl" + ";Extended Properties=Excel 8.0;HDR=YES; IMEX=1'";
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filePath + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
{
OleDbConnection oleDbConnection = new OleDbConnection(strConn);
oleDbConnection.Open();
//获取excel表
DataTable dataTable = oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);