↓ Ir para o conteúdo principal

← todas as notas

📎 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 Movie record with Id, Name, and StreamingService fields that match the column names.
  • A new ExcelMapper instance calls FetchAsync<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 changes StreamingService to disney+.
  • The modified rows are copied with C# 9 with expressions and saved with SaveAsync, using sheetName: 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.