【发布时间】:2017-12-07 13:08:55
【问题描述】:
我已成功将 word doc 转换为 pdf - 但我无法结束 winword 进程。
Dim wordApplication As Object = New Microsoft.Office.Interop.Word.Application
Dim wordDocument As Object
wordApplication.displayalerts = Word.WdAlertLevel.wdAlertsNone
wordDocument = New Microsoft.Office.Interop.Word.Document
'wordDocument = Nothing
Dim outputFilename As String
Dim filename As String
filename = "c:\TestInvoice.doc"
Try
wordDocument = wordApplication.Documents.Open(filename, ReadOnly:=False)
outputFilename = System.IO.Path.ChangeExtension(filename, "pdf")
If Not wordDocument Is Nothing Then
wordDocument.ExportAsFixedFormat(outputFilename, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, False, Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen, Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument, 0, 0, Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent, True, True, Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateNoBookmarks, True, True, False)
End If
'Threading.Thread.Sleep(3000)
If File.Exists(System.IO.Path.ChangeExtension(filename, "pdf")) Then
MessageBox.Show(System.IO.Path.ChangeExtension(filename, "pdf"))
End If
'wordDocument = Nothing
'wordApplication.Documents(filename).Close(Word.WdSaveOptions.wdDoNotSaveChanges)
'wordDocument.dispose()
'wordApplication.quit(False)
wordDocument.close()
wordApplication.application.quit(False)
wordApplication = Nothing
我已经尝试了几乎所有方法,并且在过去的几天里一直在摸不着头脑 - 你能指出我正确的方向吗?
【问题讨论】:
-
The proper way to dispose Excel com object using VB.NET? 的可能重复项 - 特别是,请参阅 the answer by Govert。
-
@AndrewMorton - 不幸的是已经尝试了所有这些 - 但无法让 releaseObject 工作 - 它无法识别
-
如果您查看 Govert 的答案,它会告诉您如何操作。另外,请参阅 my answer 到另一个使用 Govert 答案的问题。
-
stackoverflow.com/questions/15697282/… 这可能会对你有所帮助。
-
@AndrewMorton 我想我明白你在说什么,如果我错了,请纠正我我需要创建一个子程序,它首先调用处理 word 文档的子程序,然后在完成其工作量后它将调用垃圾回收