我正在尝试查询和筛选c#中的oledatatable,而不是excel中的vba。
string strSQL = "SELECT * FROM [Sheet1$] WHERE [Columns1$] is not null"; // to filter out any empty values, works if used column name like [UserInfo].
OleDbCommand cmd = new OleDbCommand(strSQL, connExcel);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(da);
dtData = new DataTable();
DataSet dtDataT = new DataSet();
dtData.Locale = System.Globalization.CultureInfo.InvariantCulture;
string FilePath = copyfile.ToString();
da.Fill(dtData);
代替 [Columns1$]
我试过了 Columns(1)
, Columns(A)
,未成功。
1条答案
按热度按时间4ioopgfo1#
您需要在连接字符串中指定hdr=no,之后列名称将自动指定为f1、f2等。
https://www.connectionstrings.com/excel/