3xGuy
3xGuy

Reputation: 2559

C# open and edit excel file inside windows forms

What I've done: I am trying to be able to open an excel file in a windows form so that I can create a disposable pivot table. I have tried a few options that I've found on Google but I've run into a brick wall. One option that I found was to open in wpf user control document viewer, while I can open the file I cannot edit it.

I have not figured out a way to edit the excel file. My Question: I need to display a blank excel sheet inside a windows form, then I will need to add a pivot table to the sheet that is embedded inside the windows form where when the form closes it disregards the sheet that was open in the form. What is the best way to do this?

Upvotes: 0

Views: 1958

Answers (1)

Michael Gunter
Michael Gunter

Reputation: 12811

For all tasks related to programmatic construction or manipulation of Office documents, the Open XML SDK is the proper solution. All other APIs are either limited in scope (other 3rd-party Excel writer APIs support only a subset of the features of Excel documents) or have issues being used programmatically (Office automation is notoriously error-prone and should NEVER be used in a server environment). The Open XML SDK allows you to directly create and manipulate the data structure that is the Office document. It does not require Office to be installed. Additionally, the Open XML Productivity tool (also available via the download link below) will allow you to open an existing document and see EXACTLY the code required to construct EXACTLY that document. Very useful!

Download: https://www.microsoft.com/en-us/download/details.aspx?id=30425

Upvotes: 1

Related Questions