Why does Excel not close after building PDF?

给你一囗甜甜゛ 提交于 2019-12-13 15:50:41

问题


I use this code to convert an excel file to PDF. The problem is that the Excel process is not close. What am I missing?

        protected void Indexchanged_ConvertPDF(Object sender, EventArgs e)
    {
        Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

        xlApp.DisplayAlerts = false;
        xlApp.Visible = false;
        xlApp.ScreenUpdating = false;

        string path = CertificadosPresion.SelectedRow.Cells[0].Text;
        string CertName = CertificadosPresion.SelectedDataKey.Value.ToString();

        Workbook xlWorkbook = xlApp.Workbooks.Open(path);

        xlWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, @"C:\pdf\" + SALESID.Text + "_CertPres.pdf", 0, false, true);

        xlWorkbook.Close();
        xlApp.Quit();
        xlApp = null;
        xlWorkbook = null;

        DisposeCOMObject(xlWorkbook);
        DisposeCOMObject(xlApp);
    }

回答1:


It is not that easy as one might think. There is a nice article losing some words about this topic:

http://devcity.net/PrintArticle.aspx?ArticleID=239

But other than that I think that this question might be a duplicate of Closing Excel Application Process in C# after Data Access. There are a lot of potential solutions for your problem.



来源:https://stackoverflow.com/questions/34387026/why-does-excel-not-close-after-building-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!