領導要求匯出的Excel檔案能讓用戶指定到想匯出的檔案夾上.
我想到的是改成下載,讓客戶自己另存為進行保存.
View代碼如下
// 匯出按鈕
$("[name=FileOutputButton]").click(function () {
var form = $("form#FileOutput");
//略...
form.submit();
});
@using (Html.BeginForm("C05_01_FileOutput", "C05", FormMethod.Post, new { id = "FileOutput" }))
{
@Html.HiddenFor(model => model.YEARS);
@Html.HiddenFor(model => model.RECORDING_MONTH);
@Html.HiddenFor(model => model.InsertUpdateFlg);
}
控制臺代碼如下
public ActionResult C05_01_FileOutput(xxx form)
{
//檢索資料
......
//保存地址
string tmpPath = Request.MapPath("~/template");
tmpPath = Path.Combine(tmpPath + "/C05_01.xlsx");
string tmpDLPath = Request.MapPath("~/Tmp");
//檔案輸出
FinancialDB.fileOutput(form, tmpPath,ref tmpDLPath);
//回傳檔案
return File(new FileStream(tmpDLPath, FileMode.Open), "application/octet-stream", Server.UrlEncode("C05_01.xlsx"));
}
這么做的缺點是當前頁面要等它執行完產生下載的提示,
期間如果用戶按了畫面其它按鈕就得不到檔案了.
所以我想到,按匯出按鈕的時候 打開新的標簽頁 再執行檔案匯出處理,
可是查了好久都沒能成功.求大神幫助!!!
uj5u.com熱心網友回復:
好像自己解決了,不知道其它還有沒有更好的方式View修改如下
$("[name=FileOutputButton]").click(function () {
var form = $("form#FileOutput");
var years = year[0].options[year[0].options.selectedIndex].value;
var month=recordingMonth[0].options[recordingMonth[0].options.selectedIndex].value;
window.open('/C05/C05_01_FileOutput?year='+years+"&month="+month);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/126610.html
標籤:ASP
上一篇:xml用dom能修改xml檔案嗎
