从没有列名称的数据集中获取值

我有一个数据集填充此excelsheet:

在这里输入图像说明

方法:

[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"); } 

如果我把“Column name”replace成“Amortization”,我得到了F列中的所有值。但是我想要的值是在K列中。如果我在K1中编写了“Column header name”,我将会得到这些值。 但有没有使用这个方法吗? 我不想在该列中使用一个值(对于我来说,大多数devise问题)。

所以只是澄清:如何使用列标题名称获取单元格K5:K10中的值?

你可以使用索引而不是列名? 行[I] [ColumnIndex]

如果您只能使用索引尝试使用行[4] [10]

 result = reader.AsDataSet(); string CellValue=result.Tables[0].Rows[4][10]; reader.Close();