文件名称:用C#.net编写导入导出EXCEL文件的代码
文件大小:2KB
文件格式:TXT
更新时间:2011-11-20 06:29:54
导出EXCEL文件的代码
用C#.net编写导入导出EXCEL文件的代码 标签: string oledbcommand provider tostring microsoft ///导入: string MyFileName = @"C:\\abc.XLS"; string MyTableName = "Sheet1"; try { string MyConnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\abc.XLS;Extended Properties='Excel 8.0;HDR=NO;IMEX=1'"; string MySQL = "SELECT * FROM [" + MyTableName + "$]"; OleDbConnection myconn = new OleDbConnection(MyConnectionstring); myconn.Open(); OleDbDataAdapter adp = new OleDbDataAdapter(MySQL, myconn); adp.Fill(ds, "res"); myconn.Close(); MessageBox.Show("Excel文件:" + MyFileName + "创建成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView1.DataSource = ds.Tables["res"]; } catch(Exception ex) { MessageBox.Show(ex.Message , "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }