【发布时间】:2014-05-22 04:22:27
【问题描述】:
我有一个用这个 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");
}
如果我用“摊销”替换“列名”,我会在 F 列中获得所有值。但我想要的值在 K 列中。如果我在 K1 中写一个“列标题名称”,我将以这种方式获得值.但是有什么方法可以不用这个吗?我不想在该列中使用值(对我来说大多数设计问题)。
所以只是为了澄清一下:如何使用列标题名称获取单元格 K5:K10 中的值?
【问题讨论】:
标签: c# asp.net-mvc excel dataset