Lm th? no ? s? d?ng t? ?ng ha ? nh?n v ?t thu?c tnh ti li?u vn ph?ng v?i Visual C#.NET

D?ch tiu ? D?ch tiu ?
ID c?a bi: 303296 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?


Bi vi?t ny ch?ng t? lm th? no ? t?o m?t Microsoft Visual C#.NET Khch hng t? ?ng ha thao tng cc tnh ch?t c?a m?t ti li?u Microsoft Word. M?c d m?u m? l c? th? cho Word, cc k? thu?t tng t? c th? p d?ng khi t? ?ng ho Microsoft Excel v Microsoft PowerPoint.


T?o ra m?t khch hng t? ?ng ha cho Microsoft Word

  1. B?t ?u Visual Studio.NET.
  2. Trn cc Tp tr?nh n, nh?p vo M?i, sau b?m D an. Ch?n ?ng d?ng Windows t? cc lo?i d? n Visual C#. Form1 ?c t?o ra theo m?c ?nh.
  3. Thm m?t tham chi?u ?n Microsoft Word ?i t?ng th vi?n. thc hin vic nay, hay lam theo nhng bc sau:
    1. Trn cc D an tr?nh n, nh?p vo Thm ti li?u tham kh?o.
    2. Trn cc COM tab, xc ?nh v? tr Microsoft Word ?i t?ng th vi?n, sau b?m Ch?n.

      Chu y Microsoft Office 2003 bao g?m chnh Interop h?i ?ng (PIAs). Microsoft Office XP khng bao g?m PIAs, nhng h? c th? ?c t?i v?. ? bi?t thm chi ti?t v? Office XP PIAs, b?m vo cc s? bi vi?t d?i y ? xem bi vi?t trong c s? ki?n th?c Microsoft:
      328912 Thng tin: Microsoft Office XP PIAs c s?n ? t?i v?
    3. Nh?p vo Ok trong cc Thm ti li?u tham kh?o h?p tho?i ? ch?p nh?n c?a b?n l?a ch?n. N?u b?n ?c nh?c t?o ra hm bao cho cc th vi?n m b?n ? ch?n, b?m vo Co.
  4. Trn cc Xem tr?nh n, ch?n H?p cng c? hi?n th? h?p cng c?, v sau thm m?t nt ? Form1.
  5. B?m p Button1. C?a s? m? cho cc h?nh th?c xu?t hi?n.
  6. Trong c?a s? m?, thay th? m? sau
    private void button1_Click(object sender, System.EventArgs e)
    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 | 
                                  new object[] {strIndex} );
       Type typeDocAuthorProp = oDocAuthorProp.GetType();
       strValue = typeDocAuthorProp.InvokeMember("Value", 
                                  BindingFlags.Default |
                                  new object[] {} ).ToString();
       MessageBox.Show( "The Author is: " + strValue,"Author" );
       //Set the Subject property.
       strIndex = "Subject";
       strValue = "The Subject";
                                  BindingFlags.Default | 
                                  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,
       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",
  7. Di chuy?n trn cng c?a c?a s? m?, v sau thm d?i y d?ng cu?i cng c?a danh sch b?ng cch s? d?ng ch? th?:
    using Microsoft.Office.Core;
    using Word = Microsoft.Office.Interop.Word;
    using System.Reflection;
  8. Nh?n F5 ? ch?y cc ?ng d?ng.
Chu y Cc DocumentProperties v cc DocumentProperty giao di?n l giao di?n b? rng bu?c vo cu?i. S? d?ng cc giao di?n ny, b?n ph?i ch?a tr? cho h? nh b?n s? m?t IDispatch giao di?n.


? bi?t thm chi ti?t, truy c?p vo cc nh pht tri?n Microsoft sau y Trang Web m?ng:
Vn ph?ng Microsoft pht tri?n v?i Visual Studio
http://msdn2.Microsoft.com/en-US/Library/aa188489 (office.10) .aspx
bit thm thng tin, bm vao s bai vit sau xem bai vit trong C s Kin thc Microsoft:
303294Lm th? no ? s? d?ng t? ?ng ha ? nh?n v ?t thu?c tnh ti li?u vn ph?ng v?i Visual Basic.NET

Thu?c tnh

ID c?a bi: 303296 - L?n xem xt sau cng: 26 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • 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 Standard Edition
T? kha:
kbpia kbautomation kbhowto kbmt KB303296 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:303296

Cung cp Phan hi


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