Hi All,
I have a Application where in I have to open a Excel and write few data, save it in my project folder and at the end I have to end excel process as there is a looping in my code.
I have done the following.
using Microsoft.Office.Interop.Excel;
Application docExcel = new Microsoft.Office.Interop.Excel.Application();
docExcel.Visible = false;
docExcel.DisplayAlerts = false;
string excelloc = Server.MapPath("~/Temp/Bulk Upload.xlsx");
_Workbook workbooksExcel = docExcel.Workbooks.Open(@excelloc, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
_Worksheet worksheetExcel = (_Worksheet)workbooksExcel.ActiveSheet;
try
{
//do your code here.
workbooksExcel.Save();
}
catch(exception ex)
{
throw ex;
}
finally
{
workbooksExcel.Close(false, Type.Missing, Type.Missing);
docExcel.Application.DisplayAlerts = true;
docExcel.Application.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(docExcel);
docExcel = null;
GC.Collect();
}