/// <summary> /// Imports data from excel file /// </summary> /// <param name="fileStream">The file stream.</param> /// <param name="workSheetName">The work sheet name.</param> /// <returns>The file data as data table.</returns> public static DataTable ImportFileAsDataTable(Stream fileStream, string workSheetName) { DataTable dataTable = new DataTable(); using (ExcelReaderManager excelReaderManager = new ExcelReaderManager()) { if (!excelReaderManager.LoadDocument(fileStream)) { throw new ArgumentException("Unable to open the file"); } dataTable = ImportFileAsDataTable(excelReaderManager, workSheetName); } return(dataTable); }
/// <summary> /// Loads data from excel file /// </summary> /// <param name="fileStream">The file stream.</param> /// <param name="workSheetName">The work sheet name.</param> /// <param name="includeHeader">The include header.</param> /// <returns>The file data as list of dictionary.</returns> public static List <Dictionary <string, object> > ImportFileAsDictionary(Stream fileStream, string workSheetName, bool includeHeader = false) { List <Dictionary <string, object> > dataList = new List <Dictionary <string, object> >(); using (ExcelReaderManager excelReaderManager = new ExcelReaderManager()) { if (!excelReaderManager.LoadDocument(fileStream)) { throw new ArgumentException("Unable to open the file"); } dataList = ImportFileAsDictionary(excelReaderManager, workSheetName, includeHeader); } return(dataList); }