Looks like there is no Option fo me to set my First Row as Column Names when using the Excel Data Reader in Selenium C#

8.4k Views Asked by At

I am using the Excel Data Reader plugin to read and parse excel data, and I would like to set the "IsFirstRowAsColumnNames" to true then finding out that there is no such definition for my created IExcelDataReader object. See the "XXXXXXXXXX" from below code. I want to set my first row as column name. Now I am having "Column1", "Column 2," ......"Column n" instead.

       public DataTable ExcelDataTable(string filename)
     { 

    FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);
    IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlRead(stream);     
    excelReader.XXXXXXXXXXXX= true;
    DataSet result = excelReader.AsDataSet();
    DataTableCollection table = result.Tables;
    DataTable resultTable = table["Person"];      
    return resultTable;

        }

Thanks for your help

1

There are 1 best solutions below

1
On

[SOLVED] This property was moved to a configuration parameter on the AsDataSet() method:

Make sure the project has a reference to the ExcelDataReader.DataSet package

Remove the line of code with IsFirstRowAsColumnNames

Change the call to AsDataSet() to something like this:

var result = reader.AsDataSet(new ExcelDataSetConfiguration() {
    ConfigureDataTable = (_) => new ExcelDataTableConfiguration() {
        UseHeaderRow = true
    }
});