返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
C#

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

曦远 (DealiAxy)约 3 分钟
目录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 许可协议。转载请注明出处!

相关文章

在.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 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…