返回文章列表文章索引阅读全文
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 许可协议。转载请注明出处!

相关文章

讨论

共 0 条

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

加载评论中…