public DataSet ReadXlsx(string filepath){
public DataSet ReadXlsx(string filepath)
try { FileStream stream = File.Open(filepath, FileMode.Open, FileAccess.Read); //2. Reading from a OpenXml Excel file (2007 format; *.xlsx) IExcelDataReader excelReader2 = ExcelReaderFactory.CreateOpenXmlReader(stream); //... //4. DataSet - Create column names from first row excelReader2.IsFirstRowAsColumnNames = true; DataSet result2 = excelReader2.AsDataSet(); return result2; } catch (Exception ex) { return null; }
try
{
FileStream stream = File.Open(filepath, FileMode.Open, FileAccess.Read);
//2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader2 = ExcelReaderFactory.CreateOpenXmlReader(stream);
//... //4. DataSet - Create column names from first row
excelReader2.IsFirstRowAsColumnNames = true;
DataSet result2 = excelReader2.AsDataSet(); return result2;
}
catch (Exception ex)
return null;
Please help. Thanks.