none
在使用Microsoft.Office.Interop.Word.ApplicationClass.Document.Open()打开受保护的office文档时抛出异常,怎样才能顺利的打开? RRS feed

  • 问题

  • 主要的代码如下:

    public bool WordConvert(string docPath, string pdfPath)
            {
                bool isSuccess;
                var wdExportFormat = WdExportFormat.wdExportFormatPDF;
                Microsoft.Office.Interop.Word.ApplicationClass application = null;
                Document document = null;
                try
                {
                    application = new Microsoft.Office.Interop.Word.ApplicationClass();
                    application.Visible = false;
                    document = application.Documents.Open(docPath);
                    document.SaveAs2();
                    document.ExportAsFixedFormat(pdfPath, wdExportFormat);
                    isSuccess = true;
                }
                catch(Exception ex)
                {
                    isSuccess = false;
                }
                finally
                {
                    if (document != null)
                    {
                        document.Close();
                        document = null;
                    }
                    if (application != null)
                    {
                        application.Quit();
                        application = null;
                    }
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    GC.WaitForPendingFinalizers(); 
                }
                return isSuccess;
            }

    抛出的异常为:{System.Runtime.InteropServices.COMException (0x800A1897): Office 检测到此文件存在一个问题。为帮助保护您的计算机,不能打开此文件。

    2014年1月28日 5:17

全部回复

  • object missing = System.Reflection.Missing.Value;
                    object FileName = docPath;
                    object isVisible = true;
                    object password = "mypassword";

    document = application.Documents.Open(ref FileName, ref missing, ref readOnly, ref missing, ref password, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);


    http://feiyun0112.cnblogs.com/


    2014年1月29日 1:13
    版主