Hello,
I'm trying to read the excel sheet and save all of its data into the 2D array. The problem is, that enything I do I get the error: System.NullReferenceException. I did FOR loops, I used foreach DataRow etc. but I still fail. My latest try:
Best regards,
Mike.
I'm trying to read the excel sheet and save all of its data into the 2D array. The problem is, that enything I do I get the error: System.NullReferenceException. I did FOR loops, I used foreach DataRow etc. but I still fail. My latest try:
FileStream stream = File.Open(ExcelSourceFile, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = Path.GetExtension(ExcelSourceFile).ToLower() == ".xls" ? ExcelReaderFactory.CreateBinaryReader(stream) :ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet ds = new DataSet();
ds = excelReader.AsDataSet();
DataRowCollection drc = ds.Tables[0].Rows;
int j=0;
for (int i = 0; i < rows; i++)
{
foreach (DataColumn column in ds.Tables[0].Columns)
{
DataFromExcel[i, j] = ds.Tables[0].Rows[i][j];
j++;
}
}
There might be some stuff from my previous tries. I know it must be the easiest thing to do with this library but I can't find the correct method. Hope someone can find few minutes to write it down.Best regards,
Mike.