Share via

C# Library to write CSV / Spreadsheet / Excel files

mjeschke 40 Reputation points
2025-05-28T18:18:37.6966667+00:00

I have a requirement to buffer / hold intermediate data in a spreadsheet style file. This will serve to as a readable autosave system in event of power failure or glitch.

  • The file could be a CSV or brand specific file such as open office or excel. I've looked at numerous libraries but haven't quite settled on one.
  • Ideally I'd LOVE a Microsoft library that would do CSV files.
  • The library should also support bidirectional and random access. Eg. the same object / reference in code would allow me to both read, write, and randomly search the file.
  • It should be a well supported library. One that I'd not have to fear loosing updates on. I'd prefer a Microsoft library.

I found CSV Helper but have to have a write object and a read object. I've also found Microsoft.Office.Interop.Excel library but I don't have Microsoft office installed.

Any other suggestions?

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. mjeschke 40 Reputation points
    2025-05-30T20:05:37.3766667+00:00

    Thanks I'll give those a try.

    0 comments No comments

  2. Bruce (SqlWork.com) 83,816 Reputation points
    2025-05-28T20:56:59.7466667+00:00

    c# is a strongly typed language so object support makes sense with csv files, but most of the libraries also support dynamic objects.

    There is no Microsoft library focused on csv. there is the OpenXml sdk, which focuses on office xml file format.

    some open source are: CsvHelper, FileHelpers and CsvSharp. all these are on GitHub and have nuget packages. They are also feature complete and few have updates at this point. Only CsvHelper has had an update in the last year.

    the cvs file format does not support random access. you need to sequential read to the desired record. it also does not support random writes. if you want to make random changes, load into memory / cache, make changes, rewrite file.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.