Reputation: 5242
I have a dataset filled with this excelsheet:
The method:
[HttpPost]
public ActionResult ShowExcelFile(GetExcel model)
{
DataSet result = null;
var file = model.Files[0];
if (file != null && file.ContentLength > 0)
{
// .xlsx
IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(file.InputStream);
reader.IsFirstRowAsColumnNames = true; // if your first row contains column names
result = reader.AsDataSet();
reader.Close();
}
for (int i = 1; i < result.Tables[0].Rows.Count; i++)
{
DataRow data = result.Tables[0].Rows[i];
System.Diagnostics.Debug.Write(data.Table.Rows[i]["Column header name"]);
}
return View("ShowExcelFile");
}
If I replace "Column name" with "Amortization" I get all values in column F. But the values I want is in column K. If I write a "Column header name" in K1 I will get the values that way. But is there some way without using this? I don't wanna use a value in that column (most design issues for me).
So just for clarification: How do I get the values in cell K5:K10 with using the column header name?
Upvotes: 1
Views: 3638
Reputation: 953
Can you use index instead column names? Rows[i][ColumnIndex]
If you can use only Index try to use Rows[4][10]
result = reader.AsDataSet();
string CellValue=result.Tables[0].Rows[4][10];
reader.Close();
Upvotes: 1