62,047
社区成员
发帖
与我相关
我的任务
分享
function Excel()
{
$.post("as.ashx, { "ExcelOUT": "1" }, function (data,status) {
// $.messager.alert('提示', "文件输出成功");
//重新加载datagrid
// $("#tab").datagrid('reload');
//关闭
// $("#dd_dg").window('close');
});
}
string RealFile = HttpContext.Current.Server.MapPath("~/DownloadFile/" + filename);//真实存在的文件
if (!System.IO.File.Exists(RealFile))
{
HttpContext.Current.Response.Write("服务器上该文件已被删除或不存在!"); return;
}
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ContentType = "application/download";
string downFile = System.IO.Path.GetFileName("11223344azx");//这里也可以随便取名
string EncodeFileName = HttpUtility.UrlEncode(downFile, System.Text.Encoding.UTF8);//防止中文出现乱码
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + EncodeFileName + ";");
context.Response.BinaryWrite(System.IO.File.ReadAllBytes(RealFile));//返回文件数据给客户端下载
context.Response.Flush();
context.Response.End();
function Excel() {
var $input = $('<input>').attr({ name: "ExcelOUT", value: "1" });
var $form = $("<form>");
$form.attr({ target: '_self', method: 'post', action: 'as.ashx' }).append($input);
$form.submit();
}
var wb = new ClosedXML.Excel.XLWorkbook();
wb.Worksheets.Add(dataTable);
wb.SaveAs(fileFullPath);