question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How skip rows and cells to create the dataset?

See original GitHub issue

Hi guys.

We are using ExcelDataReader and ExcelDataReader.DataSet extension available on NuGet, to have the IExcelDataReader instance as DataSet. It works perfectly for the most of our scenarios and it show us such as a great tool.

There are some scenarios where we need to define the row and column (for sample: B3 or D4 or E10), where should start reading data and build the dataSet. For sample, I have worksheets where the data that interest me to extract start on F2 column (where F2 is the header line and above it the data).

Is there any way to specify what cell the DataSet should start reading using the configuration objects? Or how rows it should skip (for sample, 6 lines and start reading)?

Thank you.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
andersnmcommented, Dec 14, 2017

Hi!

Alas there is no way to exclude columns with AsDataSet currently.

But there are two options for skippings rows. The simplest is probably to use the FilterRow callback:

var dataset = reader.AsDataSet(new ExcelDataSetConfiguration() {
	ConfigureDataTable = _ => new ExcelDataTableConfiguration() {
		FilterRow = rowReader => rowReader.Depth > 6
	}
});

The above reads only rows when the Depth (row index) is greater than 6.

Can also skip rows before the header, with UseHeaderRow = true, and the ReadHeaderRow callback:

var dataset = reader.AsDataSet(new ExcelDataSetConfiguration() {
	ConfigureDataTable = _ => new ExcelDataTableConfiguration() {
                UseHeaderRow = true,
		ReadHeaderRow = rowReader => {
		            rowReader.Read();
		            rowReader.Read();
		            rowReader.Read();
		            rowReader.Read();
		            rowReader.Read();
		            rowReader.Read();
                }
	}
});

The above skips the 6 first rows, uses the next row as headers, then reads the rest as normal.

Which approach to use probably depends on the use case

1reaction
andersnmcommented, Dec 14, 2017

I think your first sample looks OK - it does what it needs to do. Alternatively, initialize the for-loop with the first column index to avoid the if-continue statement, f.ex for (int c = 1; c < table.Columns.Count; c++)...

The AsDataSet() options could use a new ExcelDataTableConfiguration.FilterColumn callback to configure which columns to read into the dataset. This would complement the FilterRow callback.

EDIT: Another request for the same https://github.com/ExcelDataReader/ExcelDataReader/issues/213#issuecomment-308731323

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to skip rows while reading csv file using Pandas?
How to skip rows while reading csv file using Pandas? ; use_cols, This parameter is Only uses the passed col[string list] to make...
Read more >
Import CSV Files As Pandas DataFrame With skiprows ...
Here skiprows = 1, means delete one row. By default, it will delete one row from the top. You can delete 2, 3,...
Read more >
Skip rows with datasets.Dataset.map()
Is there a way to skip rows, i.e. how do I make 0 rows in the new dataset from a row in the...
Read more >
Skip data rows and select specific data | EXCEL - YouTube
Skip data rows and select specific data | EXCEL · 007 - Excel: Split one data column into multiples · 4 Ways to...
Read more >
How to Skip a Line in Excel – Skipping Blank Lines
Choose a row or column that is needed to be skipped. · Click on the Insert option given at the upper side of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found