为什么 Excel 在生成 PDF 后没有关闭?
Why does Excel not close after building PDF?
我使用此代码将 excel 文件转换为 PDF。问题是 Excel 进程没有关闭。我错过了什么?
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);
}
这并不像人们想象的那么容易。有一篇关于这个主题的好文章遗漏了一些词:
http://devcity.net/PrintArticle.aspx?ArticleID=239
但除此之外,我认为这个问题可能与 Closing Excel Application Process in C# after Data Access 重复。您的问题有很多潜在的解决方案。
我使用此代码将 excel 文件转换为 PDF。问题是 Excel 进程没有关闭。我错过了什么?
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);
}
这并不像人们想象的那么容易。有一篇关于这个主题的好文章遗漏了一些词:
http://devcity.net/PrintArticle.aspx?ArticleID=239
但除此之外,我认为这个问题可能与 Closing Excel Application Process in C# after Data Access 重复。您的问题有很多潜在的解决方案。