[HttpGet] public IHttpActionResult ExportData() { ... var dt = ExcelHelper.ListToDataTable(list); var fileName = SysConfig.WebTempPath + Guid.NewGuid().ToString() + ".xls"; ExcelHelper.ExportToFile(dt,fileName);
//http://www.cnblogs.com/enternal/p/5417519.html HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK); FileStream fileStream = File.OpenRead(fileName); httpResponseMessage.Content = new StreamContent(fileStream); httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName =HttpUtility.UrlEncode(Path.GetFileName(fileName)) }; return ResponseMessage(httpResponseMessage); }
DF1E31DE-768E-43D7-B1DB-DE10BD031E13 From:http://www.cnblogs.com/xuejianxiyang/p/7802365.html