C#操作Excel(搜集)
????? /// <summary>
??? /// 使用oledb連接Excel
??? /// </summary>
??? /// <param name="_fileUrl"></param>
??? /// <param name="pageName"></param>
??? /// <returns></returns>
??? public DataSet ExcelConn(string _fileUrl, string pageName)
??? {
??????? string filePath = _fileUrl;
??????? OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
??????????? + filePath + ";Extended Properties=\"Excel 8.0;IMEX=1\"");
??????? conn.Open();
??????? OleDbCommand cmd = new OleDbCommand("SELECT?? *?? FROM?? [" + pageName + "$]", conn);
??????? OleDbDataAdapter da = new OleDbDataAdapter(cmd);
??????? DataSet ds = new DataSet();
??????? da.Fill(ds);
??????? conn.Close();
??????? return ds;
??? }
?
實例:導入Excel.rar
?
總結
以上是生活随笔為你收集整理的C#操作Excel(搜集)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ActionScript 3.0 Ste
- 下一篇: NetSList