[英]How can I do this “select * from [sheet1$] where column is L” in Excel using OLEDB for C#?
I had asked about this question before but since the requirements changed, I am going to seek for answers again. 我之前曾问过这个问题 ,但是由于要求已更改,因此我将再次寻求答案。
I am trying to get all of the contents within the L column of Excel or anything under the DocumentNo heading, which by the way is placed 7 cells below the first row. 我试图在Excel的L列中或DocumentNo标题下的所有内容中获取所有内容,顺便说一下,该内容位于第一行下方的7个单元格中。 So the DocumentNo data is at L:7.
因此,DocumentNo数据位于L:7。 It is followed by a blank cell, then cells of document numbers.
它后面是空白单元格,然后是文档编号的单元格。 I want to get all of the document numbers and place it in an array to be used in succeeding functions.
我想获取所有文档编号,并将其放置在数组中以在后续功能中使用。
Help on this please. 请对此提供帮助。 Thanks.
谢谢。
You can do this using a range modifier to tell it where to go 您可以使用范围修饰符来告诉它去哪里
For example if you want just L column in your example 例如,如果您只想在示例中使用L列
SELECT DocumentNo
FROM [sheet1$L7:Ll40]
This is assuming that the document numbers end at L140. 假设文档编号以L140结尾。
try
{
//Create a OLEDB connection for Excel file
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + "d:\\data.xls" + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(connectionString);
objConn.Open();
// Creating a command object to read the values from Excel file
OleDbCommand ObjCommand = new OleDbCommand("SELECT DocumentNo FROM [Sheet1$]", objConn);
// Creating a Read object
OleDbDataReader objReader = ObjCommand.ExecuteReader();
// Looping through the values and displaying
//if (objReader.
while (objReader.Read())
{
object obj = objReader["DocumentNo"];
}
//Disposing the objects
objReader.Dispose();
ObjCommand.Dispose();
objConn.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.