在.NET中读取Excel,如何获取特定行?
我从此处获取以下代码来阅读使用 C# .NET 的 Excel 文件:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbCommand command = connection.CreateCommand()
command.CommandText = "SELECT City,State FROM [Cities$]";
我只想选择从第 4 行开始的 10 行,我该怎么做?
I have got the following code from here to read an Excel file using C# .NET:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbCommand command = connection.CreateCommand()
command.CommandText = "SELECT City,State FROM [Cities$]";
I want to select only 10 rows starting from the 4th row, how can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 Excel 查询专家,但这确实有效。 使用 TOP 将查询限制为 13 行。 第一行是带有列名称的标题,因此它可能不算数。 如果我误解的话,显然会改变。 然后,跟踪行 ID 并对 4 上或之后的行执行操作。
希望这会有所帮助!
I'm no Excel querying expert, but this certainly works. Use TOP to limit the query to 13 rows. The first row is the header with column names so it may not count. Obviously change if I misunderstand. Then, keep track of a row ID and do stuff to rows on or after 4.
Hope this helps!