mvc导出excel
前端
///导出Excel function Export() { var beginTime = Ext.getCmp('ksrq').getRawValue(); var endTime = Ext.getCmp('jzrq').getRawValue(); if (!Ext.fly('frmDummy')) { var frm = document.createElement('form'); frm.id = 'frmDummy'; frm.name = id; frm.className = 'x-hidden'; document.body.appendChild(frm); } Ext.Ajax.request({ url: '/Manager/WF_Report/FileExportExcel', method: 'POST', form: Ext.fly('frmDummy'), isUpload: true, params: { 'beginTime': beginTime, 'endTime': endTime } }); }
后台
public FileResult FileExportExcel(string beginTime, string endTime) { string SQL = "SELECT * FROM p_view_mxcx WHERE p_view_param.set_beginTime('" + beginTime + "')>='" + beginTime + "' and p_view_param.set_endTime('" + endTime + "')<='" + endTime + "'"; DataTable dt = DBhelper.Query(SQL).Tables[0]; string filePath = OperateExcel.ExportToExcel(dt, DateTime.Now.ToString("yyyyMMddHHmmss")); return File(Server.MapPath(filePath), "application/ms-excel", Path.GetFileName(filePath)); }