I am using NPOI to read the excel spreadsheet .I am gettting the above mentioned error at code dr["Amount"] = row.GetCell(4). Could somebody tell me what the problem is.
XSSFWorkbook xssfwb;
using (FileStream file = new FileStream(excelPath, FileMode.Open, FileAccess.Read))
{
xssfwb = new XSSFWorkbook(file);
}
var sheet = xssfwb.GetSheetAt(0); // Change this to the worksheet you want to import.
var rows = sheet.GetRowEnumerator();
var dtExcelData = new DataTable();
var linenumber = 0;
DataRow dr;
dtExcelData.Columns.AddRange(new DataColumn[3] {
new DataColumn("AccountNumber", typeof(string)),
new DataColumn("Amount", typeof(decimal)),
new DataColumn("Sedol",typeof(string)) });
while (rows.MoveNext())
{
var row = (XSSFRow)rows.Current;
linenumber++;
if (row.GetCell(0) != null)
{
dr = dtExcelData.NewRow();
dr["AccountNumber"] = row.GetCell(1).ToString();
dr["Amount"] = row.GetCell(4);
dr["Sedol"] = row.GetCell(11).ToString();
dtExcelData.Rows.Add(dr);
}
}