简体   繁体   English

在 Excel 中读取一些行

[英]Reading some rows in Excel

I have some problems when I try to read specific rows of an Excel document.当我尝试读取 Excel 文档的特定行时遇到一些问题。

My implementation is here: Reading Excel in c# where some columns are empty .我的实现在这里: Reading Excel in c# where some columns are empty How you can see, the entire Excel is taken into a DataTable.你怎么看,整个 Excel 都被放到了一个 DataTable 中。

Now I want get a specific range of n value:现在我想获得特定范围的 n 值:

在此处输入图片说明

I think is the DataTable the problem... I think that maybe I should to obtain another DataTable... maybe using another different query?我认为是数据表的问题...我想也许我应该获得另一个数据表...也许使用另一个不同的查询?

It seems that you are using a fixed template so you can solve using different queries on different ranges.似乎您使用的是固定模板,因此您可以在不同范围内使用不同的查询来解决。

To select a particular range you can use this query:要选择特定范围,您可以使用此查询:

string query = "SELECT * FROM [YourSheet$B58:D70]";

If you know where a range starts but not the number of rows you can use this syntax:如果您知道范围从哪里开始但不知道行数,则可以使用以下语法:

string query = "SELECT * FROM [YourSheet$B58:D]";

Using HDR=NO in your connection string and changing starting row you could use this query to simplify your next operations:在您的连接字符串中使用HDR=NO并更改起始行,您可以使用此查询来简化您的下一个操作:

SELECT [F1] AS Compagnia,
    [F2] AS Agenzia,
    [F3] AS DataSinistro
FROM [YourSheet$B59:D]

Remember you can also use WHERE to filter your results or exclude empty rows;请记住,您还可以使用 WHERE 来过滤结果或排除空行; ie: IE:

SELECT [F1] AS Compagnia,
    [F2] AS Agenzia,
    [F3] AS DataSinistro
FROM [YourSheet$B59:D]
WHERE [F3] IS NOT NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM