Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

How to end the Excel process in Task Manager using C# in ASP.net

$
0
0

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();
         }

<div style="position: relative; padding-bottom: 0px; padding-left: 3px; padding-right: 3px; clear: both; padding-top: 0px;" id="Normalcontent"> <div style="margin-left: 5px;">But my Excell Application is not closing and in next loop I am getting error saying excel app is being used by another process and it cannot be accessed.</div> <div style="margin-left: 5px;"> </div> <div style="margin-left: 5px;">Kindly let me know how can I solve this problem???</div> <div style="margin-left: 12px;" id="imcontent"> </div></div>

Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>