我希望将以下使用早期绑定的代码实现为晚期绑定。我该如何在C#中实现?
当我删除Microsoft.office.interop.word引用时,会出现一些错误,这些错误在下面的代码注释中提到。 以下是我用于将Word文档转换为PDF的代码。
Type wordType = Type.GetTypeFromProgID("Word.Application");
dynamic Word = Activator.CreateInstance(wordType);
object oMissing = System.Reflection.Missing.Value;
DirectoryInfo dirInfo = new DirectoryInfo(@"\\server\folder");
FileInfo wordFile = new FileInfo(fileName);
Word.Visible = false;
Word.ScreenUpdating = false;
Object filename = (Object)wordFile.FullName;
var doc = Word.Documents.Open(ref filename);
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".doc", ".pdf");
/*Getting an error in WdSaveFormat */
object fileFormat = WdSaveFormat.wdFormatPDF;
doc.SaveAs(ref outputFileName, ref fileFormat);
/*Getting an error in WdSaveOptions */
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
/*Getting an error in _Document*/
((_Document)doc).Close(ref saveChanges);
doc = null;
Word.Quit();
MessageBox.Show("Successfully converted");