You may be best off reading it use the idatareader interface rather than a dataset. It will be quicker anyway. Not sure why you are getting null reference exceptions off top of my head though.
From: MikeKrop
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.
Read the full discussion online.
To add a post to this discussion, reply to this email ([email removed])
To start a new discussion for this project, email [email removed]
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online atcodeplex.com