akasoggybunz
akasoggybunz

Reputation: 344

Update Existing .XLSX or .CSV File in C# - Editing Spreadsheet Cells without having to open Excel Application

There are some answers on how to update excel spread sheets using c#. However all of these answers are several years old, and most require opening in excel. I am looking for a more recent solution; where I make the edits, and do this without using excel

What I'm looking to do is update an existing .xlsx file and save that file into memory then email that stream.

If you have pointers on how to save the file into memory, that would be helpful. But the real solution that I am looking for is updating an existing .xlsx file problematically using c#, not having to open excel. I don't need to add any columns or workbooks all I need to do is simply update cells.

Upvotes: 0

Views: 948

Answers (1)

dgorti
dgorti

Reputation: 1240

This is not a specific question, but perhaps there is value in addressing a few points here.

  1. Updating XLSX file: Since this is not a simple file, you can't just open using a file open operation and edit a single file. An XLSX is a complex document, saved in XML or binary or other formats. So you need an API. You can use the built in Excel Automation objects on windows or other APIs for various platforms and languages.
  2. Do I need to Open the file and launch Excel?: No you don't have to. But If you use Excel.Application or other APIs, the Excel program is launched. Whether it is visibile or not can be controlled, but Excel.exe is the software that gets the job done when you use Excel Automation Objects. Otehr APIS like closedXml or other Excel libraries may be working at the XML level, so they don't actually open excel.exe and can get the job done.
  3. Saving in memory and directly sending via email: This is a tough one. I don't think it is possible. Most of the libraries that I mentioned about, can be working on one or more of the underlying compound document parts, so once again, because it is not a simple file, you can't edit in memory and attach.

Upvotes: 1

Related Questions