I have a C# .net web app. I want a user to click a button on a webpage, the server to open an excel spreadsheet and write data to it, and the user to save the document. Th
Office automation - the usage of these Excel.Application and Excel.Workbook objects - is not recommended and not supported by Microsoft. Look:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
This means that even if yo sort out your server-side/client-side issues, you're still playing with fire, since some scenarios might work, others won't, and others will sometimes work and sometimes cause your process to hang because Excel attempts to open a pop-up notification when there isn't a console user logged onto the server. Trust me, don't do it.
The link I provided lists several alternatives to what you're trying to do, but assuming you're planning on building relatively simple Excel sheets for your user, you're better off just creating a CSV file and sending that back to the user with the appropriate header (something like Response.ContentType="application/vnd.ms-excel"
) so that the returned data will be opened by Excel by default.
You can see more answers to that question here.