我使用以下代码将doc
转换为pdf
文件,但是在打开文档时它什么也没返回:
Dim wordApplication As New Microsoft.Office.Interop.Word.Application
Dim wordDocument As Microsoft.Office.Interop.Word.Document = Nothing
Dim outputFilename As String = IIf(fileout = "", System.IO.Path.ChangeExtension(filename, "pdf"), fileout)
wordDocument = wordApplication.Documents.Open(filename)
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)
答案 0 :(得分:0)
您的代码中有许多未定义的变量: 文件输出,文件名,输出文件名。 这是一个有效的代码
Dim wordApplication As New Microsoft.Office.Interop.Word.Application
Dim wordDocument As Microsoft.Office.Interop.Word.Document = Nothing
Dim filename As String = "yourworddocument.docx"
Dim fileout As String = "yourworddocument.pdf"
wordDocument = wordApplication.Documents.Open(filename)
wordDocument.ExportAsFixedFormat(fileout, 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)