Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult CompareExcel(ExcelModel model, string submitValue, string compareOption)
- {
- TempData["firstFile"] = model.Files[0];
- TempData["secondFile"] = model.Files[1];
- if (submitValue == "Compare calculations")
- {
- var firstFile = TempData["firstFile"];
- var secondFile = TempData["secondFile"];
- if (firstFile == null || secondFile == null)
- return View("CompareExcel");
- else
- return CompareColumn(compareOption);
- }
- //Assume submitValue is "Compare calculations"
- }
- [HttpPost]
- public ActionResult CompareColumn(string compareOption)
- {
- List<Calculation> cList = new List<Calculation>();
- Calculation calc = new Calculation();
- BigModel m = new BigModel();
- HttpPostedFileBase firstFile = (HttpPostedFileBase)TempData["firstFile"];
- HttpPostedFileBase secondFile = (HttpPostedFileBase)TempData["secondFile"];
- DataSet firstSet = ExcelToDataSet.ConvertToDataSet(firstFile);
- DataSet secondSet = ExcelToDataSet.ConvertToDataSet(secondFile);
- for (var i = 0; i < firstSet.Tables[0].Rows.Count; i++) //Get Object reference not set to an instance of an object
- {
- DataRow data = firstSet.Tables[0].Rows[i];
- calc.PresentValue = Convert.ToDecimal(data.Table.Rows[i]["Capital balance"]);
- }
- return View();
- }
- public partial class GetExcel
- {
- public List<HttpPostedFileBase> Files { get; set; }
- public GetExcel()
- {
- Files = new List<HttpPostedFileBase>();
- }
- }
- public static DataSet ConvertToDataSet(HttpPostedFileBase excelFile)
- {
- DataSet result = null;
- if (excelFile != null && excelFile.ContentLength > 0)
- {
- // .xlsx
- IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(excelFile.InputStream);
- // .xls
- //IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(file.InputStream);
- reader.IsFirstRowAsColumnNames = true; // if your first row contains column names
- result = reader.AsDataSet();
- reader.Close();
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement