1、HTML部分代码
2、js部分
function valueImportFile() { initialize(); var file = $("#valueFilePath").val(); var year = $("#yearChooseValue").combobox("getValue"); var month = $("#monthChooseValue").combobox("getValue"); //alert(year); //alert(month); //alert(file); $.ajax({ url: "@Url.Action("importMeasureData")", data: "fileName="+file+"&yearChoose="+year+"&monthChoose="+month, //"fileName": $("#valueFilePath").val(), //"yearChoose": $("#yearChooseValue").val(), //"monthChoose": $("#monthChooseValue").val() // data: formToObject($("#dateValue_form")), type: "POST", success: function (msg) { if (msg=="OK") { removecloud(); $.messager.confirm('提示信息', '更新成功!', function (info) { if (info == true) { location.reload(); } }); } else { alert(msg); removecloud(); } } }); }
3、后台方法
public JsonResult importMeasureData(string fileName, string yearChoose) { string returnInfo = "OK"; FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read); ExcelHelp excel = new ExcelHelp(file); DataTable DtTemp = new DataTable(); DataTable dt = excel.ToDataTable1(DtTemp); string[] MesArr = new string[dt.Rows.Count - 4]; bool ColumnsCheckFlag = false; bool flag = false; //bool ExecuteFlag = false; if (dt.Columns.Count == 9 && (dt.Rows[2][0].ToString() == "测点编号" && dt.Rows[2][1].ToString() == "规格" && dt.Rows[2][2].ToString() == "容积" && dt.Rows[2][3].ToString() == "温度" && dt.Rows[2][4].ToString() == "压力" && dt.Rows[2][5].ToString() == "介质" && dt.Rows[2][6].ToString() == "材质" && dt.Rows[2][7].ToString() == "原始壁厚" && dt.Rows[2][8].ToString() ==yearChoose+ "年测量值")) { //DO SOMETHING}