普通文档没有问题,如果是带密码的文档就打不开了
也不抛错。
谁能告诉怎样才能打开,或者抛错也可以!!!

解决方案 »

  1.   

    private void btnOpenWord_Click(object sender, System.EventArgs e)
    {
    string FileName = "e:\\test.doc"; if(FileName == "") return; try
    {
    Word.ApplicationClass thisApplication =
    new  Word.ApplicationClass();
                
    thisApplication.Visible = true;
    thisApplication.Caption = "";
    thisApplication.Options.CheckSpellingAsYouType = false;
    thisApplication.Options.CheckGrammarAsYouType = false; Object filename = FileName;
    Object ConfirmConversions = false;
    Object ReadOnly = false;
    Object AddToRecentFiles = false; Object PasswordDocument = System.Type.Missing;
    Object PasswordTemplate = System.Type.Missing;
    Object Revert = System.Type.Missing;
    Object WritePasswordDocument = System.Type.Missing;
    Object WritePasswordTemplate = System.Type.Missing;
    Object Format = System.Type.Missing;
    Object Encoding = System.Type.Missing;
    Object Visible = System.Type.Missing;
    Object OpenAndRepair = System.Type.Missing;
    Object DocumentDirection = System.Type.Missing;
    Object NoEncodingDialog = System.Type.Missing;
    Object XMLTransform = System.Type.Missing; // Microsoft.Office.Interop.Word.DocumentClass wordDoc =
    // wordApp.Documents.Open(ref filename, ref ConfirmConversions,
    // ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
    // ref Revert,ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
    // ref Encoding, ref Visible);
    // Microsoft.Office.Interop.Word.DocumentClass wordDoc =
    // wordApp.Documents.Open(ref filename, ref ConfirmConversions,
    // ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
    // ref Revert,ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
    // ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog); Word.Document wordDoc =
    thisApplication.Documents.Open(ref filename, ref ConfirmConversions,
    ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
    ref Revert,ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
    ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection,
    ref NoEncodingDialog, ref XMLTransform ); Word.Document thisDocument = wordDoc; Word.FormFields formFields = wordDoc.FormFields;

    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.ToString()); }
    }