P
Pingpong689
Guest
I need to read all rows in a *.xlsx file by looping each row and read each cell value within a row, by using column name like below.
public void ReadCSV(byte[] content){
MemoryStream stream = new MemoryStream();
stream.Write(content, 0, content.Length);
stream.Position = 0;
IExcelDataReader excelReader = ExcelReaderFactory.CreateReader(stream);
DataSet result = excelReader.AsDataSet();
//exception occurs below:
result.Tables[0].Rows[1]["ColA"]
}
However, an error occurs.
System.ArgumentException
HResult=0x80070057
Message=Column 'ColA' does not belong to table Sheet1.
Source=System.Data.Common
StackTrace:
at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName)
Below works, but the column name is not the name on excel file.
result.Tables[0].Rows[1]["Column0"]
Below results in `not implemented` exception, can anyone confirm this is correct?
var aIndex = excelReader.GetOrdinal("ColA");
var c = (string)excelReader["ColA"];
[1]:
Continue reading...
public void ReadCSV(byte[] content){
MemoryStream stream = new MemoryStream();
stream.Write(content, 0, content.Length);
stream.Position = 0;
IExcelDataReader excelReader = ExcelReaderFactory.CreateReader(stream);
DataSet result = excelReader.AsDataSet();
//exception occurs below:
result.Tables[0].Rows[1]["ColA"]
}
However, an error occurs.
System.ArgumentException
HResult=0x80070057
Message=Column 'ColA' does not belong to table Sheet1.
Source=System.Data.Common
StackTrace:
at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName)
Below works, but the column name is not the name on excel file.
result.Tables[0].Rows[1]["Column0"]
Below results in `not implemented` exception, can anyone confirm this is correct?
var aIndex = excelReader.GetOrdinal("ColA");
var c = (string)excelReader["ColA"];
[1]:
Continue reading...