public DataTable ConvertToDataTable(string fileName, string sheetName) { if (string.IsNullOrEmpty(sheetName)) { sheetName = GetFirstSheetName(fileName); } DataTable table = ConvertToDataTableWithoutData(fileName, sheetName); //if (!ConfirmSheetNameOrGetFirstIfNull(fileName, ref sheetName)) //{ // throw new DuradosException("Sheet name was not found in the Excel file!"); //} ExcelHandler excelHandler = new ExcelHandler(fileName, sheetName); if (excelHandler.ReadDocument(table.Columns.Count, ref table)) { excelHandler.Dispose(); for (int i = 0; i < table.Columns.Count; i++) { table.Columns[i].ColumnName = table.Rows[0][i].ToString(); } table.Rows.RemoveAt(0); //...so i'm taking it out here. return(table); } throw new FileNotFoundException("Failed to convert Excel to data table"); }
public void AddRow(string[] rowData) { switch (_dataResultType) { case DataResultType.DataTableType: while (_table.Columns.Count < rowData.Length) { _table.Columns.Add(ExcelHandler.GetColumnName(_table.Columns.Count)); } _table.Rows.Add(rowData); break; case DataResultType.ListType: _list.Add(rowData); break; default: throw new ArgumentOutOfRangeException("DataResult.DataResultType does not exist"); } }