How to pass in multiple Excel sheets as data table when using Excel Data Reader?

How to pass in multiple Excel sheets as data table when using Excel Data Reader?

Danny DannyDanny Danny Posts: 1Questions: 0Answers: 0

Dear All;
I would like to know how I can pass in more than just one "sheet" in below code?
I am filling some data and when information on "Sheet1" are filled up, I'd like to fill in information from "Sheet2".

public DataTable ExcelToDataTable(string filename)
{

        FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);
        IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

        DataSet result = excelReader.AsDataSet(new ExcelDataSetConfiguration()
        {
            ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
            {
                UseHeaderRow = true
            }
        });
        DataTableCollection table = result.Tables;
       DataTable resultTable = table["sheet1"];

       return resultTable;

    }

Replies

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    This forum is for the Javascript library DataTables. For help with the .NET library that shares the same name, please refer to the MSDN documentation.

    Allan

This discussion has been closed.