HOWTO: Visual C# .NET¿¡¼­ ÀÚµ¿È­¸¦ »ç¿ëÇÏ¿© Office ¹®¼­ ¼Ó¼ºÀ» °¡Á®¿À°í ¼³Á¤Çϱâ

±â¼ú ÀÚ·á: 303296 - ÀÌ ¹®¼­°¡ Àû¿ëµÇ´Â Á¦Ç° º¸±â.
ÀÌ ¹®¼­´Â ÀÌÀü¿¡ ´ÙÀ½ ID·Î ÃâÆÇµÇ¾úÀ½: KR303296
¸ðµÎ È®´ë | ¸ðµÎ Ãà¼Ò

¿ä¾à

ÀÌ ¹®¼­¿¡¼­´Â Word ¹®¼­ÀÇ ¼Ó¼ºÀ» Á¶ÀÛÇÏ´Â Visual C# .NET ÀÚµ¿È­ Ŭ¶óÀÌ¾ðÆ®¸¦ ¸¸µå´Â ¹æ¹ýÀ» º¸¿©ÁÝ´Ï´Ù. ÀÌ ¹®¼­ÀÇ ¿¹Á¦´Â Word¸¦ ÀÚµ¿È­Çϵµ·Ï ÀÛ¼ºµÈ °ÍÀÌÁö¸¸ Excel°ú PowerPoint¿¡µµ °°Àº ±â¼úÀ» Àû¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.

Ãß°¡ Á¤º¸

Microsoft WordÀÇ ÀÚµ¿È­ Ŭ¶óÀÌ¾ðÆ® ¸¸µé±â

  1. Visual Studio .NETÀ» ½ÃÀÛÇÕ´Ï´Ù. ÆÄÀÏ ¸Þ´º¿¡¼­ »õ·Î ¸¸µé±â¸¦ ´©¸¥ ´ÙÀ½ ÇÁ·ÎÁ§Æ®¸¦ ´©¸¨´Ï´Ù. Visual C# ÇÁ·ÎÁ§Æ® Çü½Ä¿¡¼­ Windows ÀÀ¿ë ÇÁ·Î±×·¥À» ¼±ÅÃÇÕ´Ï´Ù. ±âº»ÀûÀ¸·Î Form1ÀÌ »ý¼ºµË´Ï´Ù.
  2. Microsoft Word Object Library¿¡ ´ëÇÑ ÂüÁ¶¸¦ Ãß°¡ÇÕ´Ï´Ù. ÀÌ·¸°Ô ÇÏ·Á¸é ´ÙÀ½ ´Ü°è¸¦ ¼öÇàÇÕ´Ï´Ù.
    1. ÇÁ·ÎÁ§Æ® ¸Þ´º¿¡¼­ ÂüÁ¶ Ãß°¡¸¦ ´©¸¨´Ï´Ù.
    2. COM ÅÇ¿¡¼­ Microsoft Word Object Library¸¦ ã¾Æ ¼±ÅÃÀ» ´©¸¨´Ï´Ù.

      Âü°í: Word °³Ã¼ ¶óÀ̺귯¸®¿¡´Â ¹öÀü ¹øÈ£°¡ Æ÷ÇԵǾî Àִµ¥, Word 2000ÀÇ ¹öÀüÀº 9.0À̰í Word 2002ÀÇ ¹öÀüÀº 10.0ÀÔ´Ï´Ù.
    3. ÂüÁ¶ Ãß°¡ ´ëÈ­ »óÀÚ¿¡¼­ È®ÀÎÀ» ´­·¯ ¼±Åà ³»¿ëÀ» Àû¿ëÇÕ´Ï´Ù. ¼±ÅÃÇÑ ¶óÀ̺귯¸®¿¡ ´ëÇØ ·¡ÆÛ¸¦ ¸¸µé °ÍÀÎÁö ¹¯´Â ¸Þ½ÃÁö°¡ ³ªÅ¸³ª¸é ¿¹¸¦ ´©¸¨´Ï´Ù.
  3. º¸±â ¸Þ´º¿¡¼­ µµ±¸ »óÀÚ¸¦ ¼±ÅÃÇÏ¿© µµ±¸ »óÀÚ¸¦ Ç¥½ÃÇϰí Form1¿¡ ButtonÀ» Ãß°¡ÇÕ´Ï´Ù.
  4. Button1À» µÎ ¹ø ´©¸¨´Ï´Ù. ÇØ´ç Æû¿¡ ´ëÇÑ ÄÚµå âÀÌ ³ªÅ¸³³´Ï´Ù.
  5. ÄÚµå â¿¡¼­ ´ÙÀ½ Äڵ带
    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 | 
                                  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);
    }

  6. ¾Æ·¡ÀÇ ÄÚµå·Î ´ëüÇÕ´Ï´Ù. ÄÚµå âÀÇ ¸Ç À§·Î ½ºÅ©·ÑÇÏ¿© using Áö½Ã¹®ÀÇ ¸ñ·Ï ³¡¿¡ ´ÙÀ½ ÇàÀ» Ãß°¡ÇÕ´Ï´Ù. Word 2000ÀÇ °æ¿ì:
    using System.Reflection;
    using Office;  //Office 2000
    Word 2002ÀÇ °æ¿ì:
    using System.Reflection;
    using Microsoft.Office.Core; //Office XP
  7. ¾Æ·¡ÀÇ ÄÚµå·Î ´ëüÇÕ´Ï´Ù. F5 ۸¦ ´­·¯ ÀÀ¿ë ÇÁ·Î±×·¥À» ½ÇÇàÇÕ´Ï´Ù.
Âü°í: DocumentProperties ¹× DocumentProperty ÀÎÅÍÆäÀ̽º´Â Èı⠹ÙÀεù(late bound) ÀÎÅÍÆäÀ̽ºÀÔ´Ï´Ù. ÀÌ·¯ÇÑ ÀÎÅÍÆäÀ̽º¸¦ »ç¿ëÇÏ·Á¸é IDispatch ÀÎÅÍÆäÀ̽º¸¦ ó¸®ÇÏ´Â °Íó·³ ó¸®ÇØ¾ß ÇÕ´Ï´Ù.

ÂüÁ¶

ÀÚ¼¼ÇÑ ³»¿ëÀº ´ÙÀ½ Microsoft Developer Network À¥ »çÀÌÆ®¸¦ ÂüÁ¶ÇϽʽÿÀ.
Visual Studio¸¦ »ç¿ëÇÏ¿© Microsoft Office °³¹ßÇϱâ
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx
ÀÚ¼¼ÇÑ ³»¿ëÀº Microsoft ±â¼ú ÀÚ·áÀÇ ´ÙÀ½ ¹®¼­¸¦ ÂüÁ¶ÇϽʽÿÀ.
303294 HOWTO: Use Automation to Get and Set Office Document Properties with Visual Basic .NET

¼Ó¼º

±â¼ú ÀÚ·á: 303296 - ¸¶Áö¸· °ËÅä: 2007³â 1¿ù 17ÀÏ ¼ö¿äÀÏ - ¼öÁ¤: 3.1
º» ¹®¼­ÀÇ Á¤º¸´Â ´ÙÀ½ÀÇ Á¦Ç°¿¡ Àû¿ëµË´Ï´Ù.
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Excel 2002 Standard Edition
  • Microsoft PowerPoint 2000 Standard Edition
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft Word 2000 Standard Edition
  • Microsoft Word 2002 Standard Edition
Ű¿öµå:?
kbhowto kbautomation _ik11561 kbword kbexcel kbgrpdso KB303296

Çǵå¹é º¸³»±â