我刚接触C#,正在尝试使用以下代码读取XLSX文件:
string Connection = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=c:\\Temp\\source.xlsx;Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\";";
//code to read the content of format file
OleDbConnection con = new OleDbConnection(Connection);
OleDbCommand command = new OleDbCommand();
DataTable dt = new DataTable();
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Tabelle1$]", con);
myCommand.Fill(dt);
Console.Write(dt.Rows.Count);
我能得到正确的输出数量,但我还有两个问题:
1. 如何创建一个带有条件语句的select查询(如何访问行)?
select * from [Tabelle1$] where A = '123' (A being an existing Excel row)
会抛出一个提到错误参数的错误...
2.有人能提供给我一个教程链接或者简短示例,如何访问这些数据吗?