My Excelsheet looks like this:
http://cdn.imghack.se/images/cdc24215d3d5079628a58878520c3028.png
Here is the part of my method that matters:
My model:
http://cdn.imghack.se/images/1fd5dab2a891c3adda8cd33114ef07c1.png
It works fine and I get all values from column "Amortization" in output. Both files are .xlsx
Can anyone help me with this?
http://cdn.imghack.se/images/cdc24215d3d5079628a58878520c3028.png
Here is the part of my method that matters:
[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);
// .xls
//IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(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]["Amortization"]);
}
return View("ShowExcelFile");
}
System.Diagnostics.Debug.Write gives me no output, like "Amortization" doesn't exist.My model:
public class GetExcel
{
public List<HttpPostedFileBase> Files { get; set; }
public GetExcel()
{
Files = new List<HttpPostedFileBase>();
}
}
My HTML:@using (Html.BeginForm("ShowExcelFile", "ShowExcel", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.TextBoxFor(m => m.Files, new { type = "file", name = "Files" })<br />
<input type="submit" value="Upload file" />
}
But when I use this Excelsheet:http://cdn.imghack.se/images/1fd5dab2a891c3adda8cd33114ef07c1.png
It works fine and I get all values from column "Amortization" in output. Both files are .xlsx
Can anyone help me with this?