键入mismatch error-csharp将单词转换为PDF

时间:2013-07-03 10:19:42

标签: c# .net visual-studio-2010 ms-word office-interop

我正在尝试将文档转换为PDF。打开PDF后出现错误

Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();

object _MissingValue = System.Reflection.Missing.Value;

public void WordtoPdf_Input() //word to PDf conversion
{
    string filename_doc=System.IO.Path.GetFileName(LblFleip.Text);
    string wordFileName = LblFleip.Text;
    string pdfFileName=string.Empty;

    appWord.Visible = false;
    appWord.ScreenUpdating = false;

    // Cast as Object for word Open method
    object filename = (object)wordFileName;

    // Use the dummy value as a placeholder for optional arguments
    Microsoft.Office.Interop.Word.Document doc = appWord.Documents.Open(ref filename, ref _MissingValue,
       ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
       ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
       ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue);
    doc.Activate();

    InputFilename = pdfFileName = Path.ChangeExtension(wordFileName, "pdf");
    object fileFormat = WdSaveFormat.wdFormatPDF;

    //  i got error over here -------- error ErrorWhile opening PDFand Type mismatch.
    //(Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

    doc.SaveAs(ref outputFileName,
       ref fileFormat, ref _MissingValue, ref _MissingValue,
       ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
       ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
       ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue);

    // Close the Word document, but leave the Word application open.
    // doc has to be cast to type _Document so that it will find the
    // correct Close method.    
    object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
    ((_Document)doc).Close(ref saveChanges, ref _MissingValue, ref _MissingValue);
    doc = null;

    // word has to be cast to type _Application so that it will find
    // the correct Quit method.
    ((_Application)appWord).Quit(ref _MissingValue, ref _MissingValue, ref _MissingValue);
    appWord = null;
}

错误是

  打开PDF和类型mismatch.Error消息时出现

错误(HRESULT异常:0x80020005(DISP_E_TYPEMISMATCH))

0 个答案:

没有答案