用什么编码读获取的都是乱码吧?
采用NPOI读取Excel文件 参考 http://www.cnblogs.com/tonyqus/archive/2009/12/25/1631075.html
纯原生的读写Eccel文件,无需安装office
直接上代码
OpenFileDialog openfile = new OpenFileDialog();
openfile.Filter = "Excel文件(*.xls)|*.xls";
openfile.Multiselect = false;
if (openfile.ShowDialog() == DialogResult.Cancel)
return false;
string fileName = openfile.FileName;
DataSet ds = new DataSet();
string strCon = @" Provider = Microsoft.Jet.OLEDB.4.0 ; " +
@"Data Source = " + fileName + ";" +
@"Extended Properties=Excel 8.0";
OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = " SELECT * FROM [Sheet1$] ";
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(strCom, myConn);
ds = new DataSet();
myConn.Open();
myDataAdapter.Fill(ds, "[Sheet1$]");
myConn.Close();
this.dt = ds.Tables["[Sheet1$]"];
return true;