Using EPPlus-Core to Export Excel Documents in .NET Core (C#)
First, install Just install it via NuGet, super convenient. How to use There are many ways to export; this article only covers the most convenient one with the least code. First, define an entity class, for example: public class OutputData { public string Address { get; set; } public int Title { get; set; } public int Description { ge
目录3 个章节
First, install
Just install it via NuGet, super convenient.
How to use
There are many ways to export; this article only covers the most convenient one with the least code.
First, define an entity class, for example:
public class OutputData {
public string Address { get; set; }
public int Title { get; set; }
public int Description { get; set; }
public int Keywords { get; set; }
public int Content { get; set; }
public int Score { get; set; }
}
Then just pass a list of type OutputData and you can output an Excel file.
private static void ExportExcel(IEnumerable<OutputData> results) {
using var package = new ExcelPackage();
var worksheet = package.Workbook.Worksheets.Add("结果导出");
worksheet.Cells.LoadFromCollection(results, true);
package.SaveAs(new FileStream("output.xlsx", FileMode.Create));
}
Note: The second parameter of worksheet.Cells.LoadFromCollection() indicates outputting the header~
References
_EOF_
Using EPPlus-Core to Export Excel Documents in .NET Core (C#)
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
分析C#项目的单元测试覆盖率,提高代码质量
C#覆盖率分析?不就是用工具生成报告吗?VSCode、VS、Rider哪个不能干?真当这是啥高科技?
2025-08-06 · C# · 约 1 分钟
纯 C#实现+AOT 打造的多功能图片处理工具 ImageGlider
纯C#+AOT打造的ImageGlider,图像处理功能堆得像山,还非得标榜零依赖?ImageSharp封装得倒是挺顺溜,就是不知道这模块化架构能走多远。Web API和CLI工具有点东西,但别指望我夸太离谱。
2025-08-05 · C# · 约 1 分钟
在.NetCore(C#)中使用ODP-NET-Core+Dapper操作Oracle数据库
前言 虽然一直在说“去IOE化”,但是在国企和政府,Oracle的历史包袱实在太重了,甚至很多业务逻辑都是写在Oracle的各种存储过程里面实现的…… 我们的系统主要的技术栈是Django / Spring / AspNetCore,Java的不必说对Oracle支持肯定没问题,关键在于Django对Oracle版本有要求,兼容性不是特别好,Oracle版本没办法随意升级的,所以我想到用.Net
2021-12-18 · C# · 约 1 分钟
C#中的Attribute与Python-TypeScript的装饰器是同个东西吗
前言 最近成功把「前端带师」带入C#的坑~~(实际是前端带师开始从cocos转unity游戏开发了)~~ 某天,「前端带师」看到这段代码后问了个问题:[这个是装饰器]? [HttpGet] public Response Get() { return ... } 我第一反应觉得不是,这玩意在C#中叫“特性”(英文名Attribute,下文统称为特性),在Java中叫注解,虽然写法和Pyth
2022-06-26 · C# · 约 1 分钟
讨论
共 0 条加载评论中…