📎 Webclip
Read and Write Excel Spreadsheets With C#
The post presents ExcelMapper as a simple .NET package for reading and writing Excel files with POCOs, dynamic objects, and records. It works cross-platform through NPOI and also supports formulas, formatting, and sheets.
Reading notes#
- ExcelMapper is an MIT-licensed .NET OSS package for reading and writing Excel files with plain C# objects.
- It uses NPOI under the hood, so it works cross-platform instead of relying on the Windows-only Jet database engine.
- The library feels similar to Entity Framework Core or Dapper for people familiar with data access tools.
- It can also work with dynamic objects and records, along with Excel features such as formulas, formatting, and sheets.
- To read a movie spreadsheet, the post defines a
Movierecord withId,Name, andStreamingServicefields that match the column names. - A new
ExcelMapperinstance callsFetchAsync<Movie>(excelFile)to load the rows into a list. - The example then iterates through the loaded movies and prints them in the console.
- To write data back, the post creates another
ExcelMapper, reads the same rows, and changesStreamingServicetodisney+. - The modified rows are copied with C# 9
withexpressions and saved withSaveAsync, usingsheetName: disney. - After saving, the spreadsheet contains a new sheet named
disney+. - The conclusion says ExcelMapper lets .NET developers focus on the data while still using Excel as a general-purpose business tool.
