http://www.cnblogs.com/top5/archive/2010/03/12/1684559.html
--下载excel的dll
http://bbs.csdn.net/topics/390271458
http://zhidao.baidu.com/link?url=c1m-oJjceP0oXP7_Hlm2EyoD9F71SVmlERMX3pPDSRgiKJxeIaoZV0xav9jxdJm04ibUB5h05k1wi8Hjl45O6q
excel 导入到datatable
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Office.Interop.Excel; using System.IO; using System.Reflection; using System.Data.OleDb; private void Bingdgv() { if (FilePath == "") { return; } try { OleDbConnection conn = new OleDbConnection(ExcelConnStr); string sql = "select * from [Sheet1$]"; if (conn.State == ConnectionState.Closed) { conn.Open(); } OleDbDataAdapter myCommand = new OleDbDataAdapter(sql, conn); ds = new DataSet(); myCommand.Fill(ds, "[Sheet1$]"); conn.Close(); dgvData.DataMember = "[Sheet1$]"; dgvData.DataSource = ds; conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); throw ex; } }
“System.Data.DataTable”和“Microsoft.Office.Interop.Excel.DataTable”之间的不明确的引用
DataTable dt=new DataTable();了吗??
引用了 uisng System.Data;吗??
-
using Excel = Microsoft.Office.Interop.Excel;
这样就OK了,呵呵