Excel对象没有发布asp.net c#

时间:2014-11-06 10:16:29

标签: c# asp.net excel

无法在以下功能中发布Excel对象:

   public void RunM(string fileName, string sMacro)
   {
        Excel.Application xlApp = null;
        Excel.Workbooks Books = null;
        Excel.Workbook book = null;


        xlApp = new Excel.Application();
        Books = xlApp.Workbooks;
        book = Books.Open(fileName);

        object misValue = System.Reflection.Missing.Value;
        book.Application.Run(sMacro);

        xlApp.DisplayAlerts = false;
        book.Save();
        book.Close(false, Type.Missing, Type.Missing);
        xlApp.Quit();

        GC.Collect();


        if (book != null) Marshal.ReleaseComObject(book);
        if (Books != null) Marshal.ReleaseComObject(Books);
        if (xlApp != null) Marshal.ReleaseComObject(xlApp);

    }

0 个答案:

没有答案