标签:ade content result 获取 [] path window time tostring
这里提供两种下载模板的方法,第一是利用FileStream文件流下载固定的模板,第二种是利用NPOL自动生成模板
利用FileStream:
前端请求:
window.open(‘/controller/DownTemplate‘,‘_blank‘)
后端响应:
public FileStreamResult DownTemplate()
{
FileStream stream = new FileStream(Path.Combine(Server.MapPath("..\\ExcelTemplate"), "****导入模板.xlsx"), FileMode.Open, FileAccess.Read); //寻找路径下的模板
return File(stream, "application/x-excel", "****导入模板.xlsx");
}
利用NPOL:
public ActionResultDownTemplate()
{
#region 获取下载列表名数据 dic
List<Dictionary<string, string>> dic = new List<Dictionary<string, string>>();
.....................
.....................
#endregion
WriteToExcelDynamic("", dic, HttpContext, "***"导入模板 + DateTime.Now.ToString("yyyyMMdd") + ".xls");
return Content("");
}
public void WriteToExcelDynamic(string title, List<Dictionary<string, string>> data, HttpContextBase context, string fileName, string[] column)
{
ExcelReader.RenderToExcelDynamic(title, data, context, fileName, column); //此处方法与前一篇类似
}
标签:ade content result 获取 [] path window time tostring
原文地址:http://www.cnblogs.com/leap-li/p/7678198.html