Q:

Is there a way to fill out an Excel workbook without involving Excel itself? Or can I force Excel to quit?

I am creating a web page to select data to download an Excel workbook (complete with macros), with that data filled in to the appropriate cells.
I was given a .vbs as a starting point for filling out an Excel workbook.
In the .vbs, the original programmer calls
Set objExcel =  CreateObject("Excel.Application")
set ObjWorkbook =objExcel.Workbooks.Open(blankFile)
`...
objWorkbook.Saveas(outputFile)
objExcel.Quit

I'm trying to make a web page using C# and MVC, so I looked into Excel.Application and found this and this. I developed an action, just to test things out: 
public FileResult filledOutWorkbook()
{
    Excel.Application oXL;
    Excel._Workbook oWB;
    Excel._Worksheet oSheet;
    Excel.Range oRng;

    oXL = new Excel.Application();
    oXL.Visible = false;

    oWB = oXL.Workbooks.Open(Server.MapPath("~/Content/Worksheet2.xlsm"));
    oSheet = oWB.Sheets["Information Sheet"];

    oSheet.Range["V2"].Value2 = "customer test lol";

    if (!Directory.Exists(Server.MapPath("~/App_Data/temp")))
    {
        Directory.CreateDirectory(Server.MapPath("~/App_Data/temp"));
    }
    var filename = Server.MapPath("~/App_Data/temp/") + DateTime.Now.ToString("o").Replace(":", "") + ".xlsm";
    oWB.SaveCopyAs(filename);

    oXL.Visible = false;
    oXL.Quit();

    return File(filename, "application/vnd.ms-excel.sheet.macroEnabled.12", "Worksheet.xlsm");
}

(I'm going to do a scheduled task or something to clear these out because I'm pretty sure I can't just get a byte stream of the file.)
The problem is, this doesn't close Excel. Apparently C# is not interacting with a library that understands Excel workbooks' formatting, you're automating Excel. I would install Excel on the production server, but when I tell it to quit Excel it doesn't quit. It asks the user if they want to save changes to the template document. I don't know how many times this page is going to get used but I think it's bad practice to have to click "no" however many times on the server to free up memory.
Can I circumvent this? Is there a better library than the COM object Microsoft.Office.Interop.Excel? Can I force Excel to close or is my best bet to write all the Excel interaction in VB and call that from the controller action?

A:

As someone who has used and suffered with the Microsoft Excel Interoperability Library, I'm glad you are looking for an alternative.
Don't get me wrong. The interoperability library is extremely useful if you're trying to automate some simple task with small amounts of data. But it's ridiculously slow when it involves large amounts of data. And if you want this on a web server, you need to have Excel Installed on the server as well.
I suggest you use ClosedXML. It's open source and MIT licensed. It's basically a wrapper around OpenXML. It's also very easy to use, much faster and doesn't need Excel installed on the server
https://github.com/ClosedXML/ClosedXML

