Issue:
I am using the Microsoft.Office.Interop.Excel library in an ASP.NET application, and I have populated a Worksheet in a Workbook. I want the user to be prompted to Save the document to their machine, but I cannot find a way to do it (myWorkbook.SaveAs(...) doesn’t work).
Question:
How can I get the Workbook saved to the user’s machine? I’ve used Response.Write(...) to prompt the user to save a text-based file (CSV) before, but I cannot figure out how to do this for .xls files.
Bonus:
If this is not possible to do using the Microsoft.Office.Interop.Excel library, is there a free (Lesser GPL-ish) library I can use instead?
I would assume that Microsoft would have a tool for this, but we all know what assuming does…
Like @Jason Meckley said, in order to use the interop to create Excel files on the server, you need Office installed on the machine. The workaround to this is to use Open XML:
From the MSDN page:
Here are a couple of ‘getting started’ tutorials that I found useful:
Formatted Excel using SDK 2.0 and .NET
OpenXML SDK 2.0: Export a DataTable to Excel