下载Excel接口
- Controller层
[Area("Api")]
public class DownloadExcelController : Controller
{
public ActionResult DownloadFile(int categoryID,string openID)
{
IH5Service m_H5Service = IocProxyFactory.GetService<IH5Service>();
try
{
var ret = m_H5Service.Download(categoryID,openID);
string fileName = DateTime.Today.ToString("yyyy-MM-dd") + categoryEntity.CategoryName + ".xls";
HttpContext.Response.Headers.Append("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8).ToString());
HttpContext.Response.ContentType = "application/ms-excel";
HttpContext.Response.WriteAsync(ret);
return RedirectToAction("ret");
}
catch (Exception ex)
{
LogHelper.Info("Excel_Error:" + ex.ToString());
return Json("下载失败"