????? C# .NET ?? Office ???????? ??? ??? ???? ?? ??? ?? ??????? ???? ?? ??? ??????? ?? ????? ???? ????

???? ?????? ???? ??????
???? ID: 303296 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

????????? ???? ?? ?? ???? ?? ???? ?? Microsoft Visual C# .NET ????? ?? ??? ???? Microsoft Word ???????? ?? ??? manipulates ??????? ???????? ????? ??? Word ?? ??? ??????? ??, ??????? ???? ??????? ???? ???? ?? ???? ?? Microsoft Excel ?? Microsoft PowerPoint ????????

???? ???????

Microsoft Word ?? ??? ??? ??????? ??????? ?????

  1. Visual Studio .NET ?? ??????? ?????
  2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????. ??? ????Windows ??????????? ????? C# ????????? ??????? Form1 ???????? ??? ?? ???? ??..
  3. ???? ?????? ??????Microsoft Word ???????? ?????????. ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. ????? ????????????????? ??,?????? ??????.
    2. ????? ????COM??? ??, ??????Microsoft Word ???????? ??????????? ????-????? ????, ?? ???? ?????? ????.

      ???:Microsoft Office 2003 ??? ???????? Interop Assemblies (PIAs) ????? ??? Microsoft Office XP ??? PIA ????? ???? ?????, ????? ????? ??????? ???? ?? ???? ??..Office XP PIAs ?? ???? ??? ???????? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
      328912?????: Microsoft Office XP PIAs ???? ??????? ?? ??? ??????
    3. ????? ????,OK??????????? ??????????? ????? ???? ??? ?? ??????? ???? ?? ??? ??? ??? ?? ????????? ?? ?? ???? ?????? ????? ???? ?? ??? wrappers ????? ???? ?? ??? ??? ???, ?? ????? ???????.
  4. ????? ?????????????, ?? ??? ????????? ?????to display the Toolbox, and then add a button to Form1.
  5. ???-????? ????Button1. ?????? ?? ??? ??? ????? ????? ????..
  6. ??? ????? ???, ????? ??? ?? ???????????? ????
    private void button1_Click(object sender, System.EventArgs e)
    {
    }
    					
    with::
    private void button1_Click(object sender, System.EventArgs e)
    {
       Word.Application oWord;
       Word._Document oDoc;
       object oMissing = Missing.Value;
       object oDocBuiltInProps;
       object oDocCustomProps;
    			
       //Create an instance of Microsoft Word and make it visible.
       oWord = new Word.Application();
       oWord.Visible = true;
    
       //Create a new Document and get the BuiltInDocumentProperties collection.
       oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, 
                                  ref oMissing);
       oDocBuiltInProps = oDoc.BuiltInDocumentProperties;
       Type typeDocBuiltInProps = oDocBuiltInProps.GetType();
    
       //Get the Author property and display it.
       string strIndex = "Author";
       string strValue;
       object oDocAuthorProp = typeDocBuiltInProps.InvokeMember("Item", 
                                  BindingFlags.Default | 
                                  BindingFlags.GetProperty, 
                                  null,oDocBuiltInProps, 
                                  new object[] {strIndex} );
       Type typeDocAuthorProp = oDocAuthorProp.GetType();
       strValue = typeDocAuthorProp.InvokeMember("Value", 
                                  BindingFlags.Default |
                                  BindingFlags.GetProperty,
                                  null,oDocAuthorProp,
                                  new object[] {} ).ToString();
       MessageBox.Show( "The Author is: " + strValue,"Author" );
    
       //Set the Subject property.
       strIndex = "Subject";
       strValue = "The Subject";
       typeDocAuthorProp.InvokeMember("Item", 
                                  BindingFlags.Default | 
                                  BindingFlags.SetProperty, 
                                  null,oDocBuiltInProps, 
                                  new object[] {strIndex,strValue} );
    			
       //Add a property/value pair to the CustomDocumentProperties collection.
       oDocCustomProps = oDoc.CustomDocumentProperties;
       Type typeDocCustomProps = oDocCustomProps.GetType();
    
       strIndex = "Knowledge Base Article";
       strValue = "Q303296";
       object[] oArgs = {strIndex,false,
                         MsoDocProperties.msoPropertyTypeString,
                         strValue};
    
       typeDocCustomProps.InvokeMember("Add",BindingFlags.Default | 
                                  BindingFlags.InvokeMethod, null, 
                                  oDocCustomProps, oArgs );
    
       MessageBox.Show("Select \"Properties\" from the File menu "
            + "to view the changes.\nSelect the Summary tab to view "
            + "the Subject property and the Custom tab to view the Knowledge"   
            + "Base Article property.", "Check File Properties",
            MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    					
  7. Scroll to the top of the code window, and then add the following lines to the end of the list of?? ????? ????directives:
    using Microsoft.Office.Core;
    using Word = Microsoft.Office.Interop.Word;
    using System.Reflection;
    					
  8. ????????? ?? ????? ?? ??? F5 ??????
???:TheDocumentProperties??DocumentPropertyinterfaces are late bound interfaces. To use these interfaces, you must treat them like you would anIDispatch???????? ???

??????

For more information, visit the following Microsoft Developer Network Web site:
Visual Studio ?? ??? Microsoft Office ??????????
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx
???????? ??????? ?? ???, Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ????? ????::
303294How To Use Automation to Get and to Set Office Document Properties with Visual Basic .NET

???

???? ID: 303296 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Office PowerPoint 2003
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft Word 2002
??????: 
kbpia kbautomation kbhowto kbmt KB303296 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:303296

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com