1737

ExcelDataReader FilterColumn usage

Question:

I am trying to return a data set that returns the first row as the header row(this is working) as well as filter out entire columns from the data depending on their column header.

ExcelDataReader 3.4.0 introduced the FilterColumn callback option which I am attempting to utilize.

Below is my AsDataSet call

var ds = reader.AsDataSet(new ExcelDataSetConfiguration() { ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration() { // Gets or sets a value indicating whether to use a row from the // data as column names. UseHeaderRow = true, // Gets or sets a callback to determine which row is the header row. // Only called when UseHeaderRow = true. ReadHeaderRow = (rowReader) => { // F.ex skip the first row and use the 2nd row as column headers: rowReader.ToString(); }, FilterColumn = (rowReader, columnIndex) => { return //if header == "string" filter out entire column } } });

Above when I try to look at the row,index pair of the column and test to see if it contains the phrase it returns it anyway. What is the proper usage of FilterColumn in this scenario?

Link to github : <a href="https://github.com/ExcelDataReader/ExcelDataReader/tree/v3.4.0" rel="nofollow">https://github.com/ExcelDataReader/ExcelDataReader/tree/v3.4.0</a>

Answer1:

Put the headers in a list in ReadHeaderRow, and check the index in FilterColumn:

var headers = new List<string>(); ds = reader.AsDataSet(new ExcelDataSetConfiguration() { ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration() { UseHeaderRow = true, ReadHeaderRow = rowReader => { for (var i = 0; i < rowReader.FieldCount; i++) headers.Add(Convert.ToString(rowReader.GetValue(i))); }, FilterColumn = (columnReader, columnIndex) => headers.IndexOf("string") != columnIndex } });

Answer2:

It is really easy! Just use it in this way:

FilterColumn = (colReader, colIndex) => colReader[colIndex].ToString() != "string"

or

FilterColumn = (colReader, colIndex) => !colReader[colIndex].ToString().Contains("string")

Recommend

  • remove strings in between lines in a file
  • python performance problems using loops with big tables
  • Load RSA PKCS#1 private key from memory?
  • WCF net.tcp transport security - how to disable server certificate validation on the client
  • Mongo Index not being used
  • Can not find reason for crash test flight
  • How to change system locale in batch
  • Creating certificate using makecert without pvk file
  • Convert Json to List with .NET
  • gridview on page won't refresh, even when calling databind again
  • OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to api.amazonalexa.com:443
  • JAVA 7 watch service
  • How to override isEmpty method of JsonSerializer for specific class without overriding serialize met
  • iPhone — MKReverseGeocoder.adminstrativeArea — getting state abbreviation
  • CardLayout display Next panel - java Swing
  • C# List.Add not adding properly
  • Eclipse : Unknown Source Java SQL Exception
  • Why does _GET in PHP wrongly decodes slash?
  • cURL for Windows can't make a secure connection to the Stack API
  • Cleave.js Phone CA
  • Redirect response to download file
  • ASP.NET Gridview Paging Problem
  • android.app.PendingIntent cannot be accessed ouside the package
  • SSLRead() return error -9806/15958)
  • What distributed message queues support millions of queues?
  • Streaming data from a NVarchar(Max) column using c#
  • python - calculate orthographic similarity between words of a list
  • Iterate twice through a DataReader
  • SSIS Designer is running VERY slowly
  • Python to parent/child JSON
  • Python getting common name from URL using ssl.getpeercert()
  • Access user's phone number on iOS 7
  • Ajax Upload File: $_FILES is empty but files exists in request header
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • does jqgrid support a multiple checkbox list for editing
  • Microsoft Visual Studio Community 2015 always crashes in Windows 10 if swithed to Visual FoxPro
  • How to delete a row from a dynamic generate table using jquery?
  • using HTMLImports.whenReady not working in chrome
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection