1、HTML部分代码
<div id="dateValue_div" class="easyui-dialog">
<div>
<form id="dateValue_form" enctype="multipart/form-data">
<table id="dateChooseValue_table">
<tr>
<td style="width: 25%" align="right"><span>选择测量值年份:</span></td>
<td><input id="yearChooseValue" name="yearChooseValue" /></td>
</tr>
<tr>
<td style="width: 25%" align="right"><span>选择测量值月份:</span></td>
<td><input id="monthChooseValue" name="monthChooseValue" /></td>
</tr>
<tr>
<td> <input type="file" id="valueFilePath"></td>
</tr>
<tr>
<td colspan="3" align="center"> <a class="easyui-linkbutton" id="valueImportFile" onclick="valueImportFile()" iconcls="icon-ok">导入</a></td>
<td colspan="3" align="center"> <a class="easyui-linkbutton" id="showValue" onclick="showValue()" iconcls="icon-ok">确定</a></td>
</tr>
</table>
</form>
</div>
</div>
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}