Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My Excel file is not in tabular data. I am trying to read from an excel file. I have sections within my excel file that are tabular.

I need to loop through rows 3 to 20 which are tabular and read the data.

Here is party of my code:

     string fileName = "C:\Folder1\Prev.xlsx";
     var workbook = new XLWorkbook(fileName);
     var ws1 = workbook.Worksheet(1); 

How do I loop through rows 3 to 20 and read columns 3,4, 6, 7, 8? Also if a row is empty, how do I determine that so I can skip over it without reading that each column has a value for a given row.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
250 views
Welcome To Ask or Share your Answers For Others

1 Answer

To access a row:

var row = ws1.Row(3);

To check if the row is empty:

bool empty = row.IsEmpty();

To access a cell (column) in a row:

var cell = row.Cell(3);

To get the value from a cell:

object value = cell.Value;
// or
string value = cell.GetValue<string>();

For more information see the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...