区块链技术博客
www.b2bchain.cn

使用EPPlus创建后下载Excel文件 – c#程序员分享

本文介绍了使用EPPlus创建后下载Excel文件 – c#程序员分享,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

我正在使用EPPlus库生成一个excel文件,该文件已成功保存在服务器上的文件夹中。

如何将此文件下载到我的本地计算机?

这是我的代码

public void CreateExcelFirstTemplate() {       var fileName = "C:ExcelDataTestExcellData.xlsx";    var file = new FileInfo(fileName);    using (var package = new OfficeOpenXml.ExcelPackage(file))    {       var worksheet = package.Workbook.Worksheets.FirstOrDefault(x => x.Name == "Attempts");       worksheet = package.Workbook.Worksheets.Add("Assessment Attempts");       worksheet.Row(1).Height = 20;        worksheet.TabColor = Color.Gold;       worksheet.DefaultRowHeight = 12;       worksheet.Row(1).Height = 20;        worksheet.Cells[1, 1].Value = "Employee Number";       worksheet.Cells[1, 2].Value = "Course Code";        var cells = worksheet.Cells["A1:J1"];       var rowCounter = 2;       foreach (var v in userAssessmentsData)       {         worksheet.Cells[rowCounter, 1].Value = v.CompanyNumber;         worksheet.Cells[rowCounter, 2].Value = v.CourseCode;          rowCounter++;       }       worksheet.Column(1).AutoFit();       worksheet.Column(2).AutoFit();         package.Workbook.Properties.Title = "Attempts";       package.Save();   } } 

参考方案

如果要在每个请求上生成此文件,则无需将其保存在服务器上:

public void CreateExcelFirstTemplate() {        var fileName = "ExcellData.xlsx";        using (var package = new OfficeOpenXml.ExcelPackage(fileName))        {           var worksheet = package.Workbook.Worksheets.FirstOrDefault(x => x.Name == "Attempts");           worksheet = package.Workbook.Worksheets.Add("Assessment Attempts");           worksheet.Row(1).Height = 20;            worksheet.TabColor = Color.Gold;           worksheet.DefaultRowHeight = 12;           worksheet.Row(1).Height = 20;            worksheet.Cells[1, 1].Value = "Employee Number";           worksheet.Cells[1, 2].Value = "Course Code";            var cells = worksheet.Cells["A1:J1"];           var rowCounter = 2;           foreach (var v in userAssessmentsData)           {             worksheet.Cells[rowCounter, 1].Value = v.CompanyNumber;             worksheet.Cells[rowCounter, 2].Value = v.CourseCode;              rowCounter++;           }           worksheet.Column(1).AutoFit();           worksheet.Column(2).AutoFit();             package.Workbook.Properties.Title = "Attempts";           this.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";           this.Response.AddHeader(                     "content-disposition",                     string.Format("attachment;  filename={0}", "ExcellData.xlsx"));           this.Response.BinaryWrite(package.GetAsByteArray());       } }          

我正在使用Retrofit来获取JSON答复。这是我实施的一部分("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": &#03…

我正在使用Wiremock在Spring启动应用程序中模拟Junit的REST服务。我的问题是,我无法匹配多个匹配模式。 Junit.javaStringValuePattern pattern = WireMock.matching(".*"); givenThat(post(urlEqualTo("/softwares&#0…

我有一个php函数,它以JSON返回此代码{"0":{"title":"Dans lu2019appartement"},"1":{"title":"A lu2019au00e9roport – Du00e9part de Bu00e9at…

我在MVC4 ASP.NET Web应用程序中使用Jquery DataTable TableTool。导出到Excel和PDF可以与Chrome完美配合。但是不能在IE和FireFox中使用。我的代码如下 dom: 'T<"clear">lfrtip', tableTools: { "sSwfP…

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » 使用EPPlus创建后下载Excel文件 – c#程序员分享
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们