I am dynamically creating a Excel File that is displayed to the users upon creation, however I now need to also save the file onto the server.
How would I save it to a specific folder?
I have the following code
public void ExportMembers()
{
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
ws.Cells[1, 1] = "Site Id";
//I create the rest of the cells here
xla.Visible = true; //this displays the excel spreadsheet to the user
//client id code is here
if (!System.IO.Directory.Exists("/Files/" + clientId + "/Excel"))
{ //if doesn't exist make folder
System.IO.Directory.CreateDirectory("/Files/" + clientId);
System.IO.Directory.CreateDirectory("/Files/" + clientId + "/Excel");
}
//save the xla as a file Here
}
How do I save the spreadsheet on the server?
Any help is appreciated.
Thanks
see the Save method for Microsoft.Office.Interop.Excel.Application
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.save