<script> var X = XLSX; var fileUpload = document.getElementById('fileUpload'); function uploadFile(e) { var files = e.target.files; var f = files[0]; { var reader = new FileReader(); var name = f.name; reader.onload = function (e) { var data = e.target.result; var workbook = XLSX.read(data, { type: 'binary' }); var result = {}; workbook.SheetNames.forEach(function (sheetName) { var roa = X.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]); if (roa.length > 0) { result[sheetName] = roa; } }); var output = JSON.stringify(result, 2, 2); jQuery.ajax({ type: "POST", url: "@Url.Action("UploadData", "MyController")", dataType: "json", data: { dataToUpload: output }, success: function (successMsg) { alert(successMsg.records); } }); } reader.readAsBinaryString(f); } } if (fileUpload.addEventListener) fileUpload.addEventListener('change', uploadFile, false); </script>
var workbook = XLSX.read(data, { type: 'binary' }); var result = {}; workbook.SheetNames.forEach(function (sheetName) { var roa = X.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]); if (roa.length > 0) { result[sheetName] = roa; } });
[HttpPost] public ActionResult DataUpload(FormCollection formCollection) { string dataToUpload = formCollection["dataToUpload"]; int recordsUploaded = 0; GroupDTO groupDTO = JsonConvert.DeserializeObject(dataToUpload); // do something with the data return Json(new { records = string.Concat(“Total records”, recordsUploaded)}); }
public class GroupDTO { public ListData { get; set; } public long ChurchId { get; set; } } public class GroupJson { public string Name { get; set; } public string Description { get; set; } }
Share this page on
1
People Like(s) This Page
Permalink
comments powered by Disqus