我想用閱讀在C#中的Excel文件下面的代碼查詢Excel工作表在c#
string excelFileName = "Book2.xls";
string excelConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Book2.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
//string excelConnectString = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + excelFileName + ";" + "Extended Properties = Excel 8.0; HDR=Yes;IMEX=1";
OleDbConnection objConn = new OleDbConnection(excelConnectString);
OleDbCommand objCmd = new OleDbCommand("Select * From [Sheet1$]", objConn);
OleDbDataAdapter objDatAdap = new OleDbDataAdapter();
objDatAdap.SelectCommand = objCmd;
DataSet ds = new DataSet();
objDatAdap.Fill(ds);
一切工作fine.Now我的要求是讀取Excel文件類似下面
SELECT A,B,D From [Sheet1];
你想使用列名搜索? – Anuraj
@Anuraj:沒有像'從表中選擇A,B,C'的單元格 –
我認爲你不能這樣做......一個小的解決方法是使一個「Select *」填充數據集,並從數據集... – 2GDev