방법: 프로그래밍 방식으로 문서에 머리글 및 바닥글 추가
Section의 Headers 속성 및 Footers 속성을 사용하여 문서의 머리글 및 바닥글에 텍스트를 추가할 수 있습니다.문서의 각 섹션에는 세 개의 머리글 및 바닥글이 있습니다.
문서 수준 사용자 지정에 대한 절차와 응용 프로그램 수준 추가 기능에 대한 절차는 다릅니다.
적용 대상: 이 항목의 정보는 Word 2013 및 Word 2010의 문서 수준 프로젝트 및 응용 프로그램 수준 프로젝트에 적용됩니다. 자세한 내용은 Office 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.
문서 수준 사용자 지정
다음 코드 예제를 사용하려면 프로젝트의 ThisDocument 클래스에서 코드 예제를 실행하십시오.
문서의 바닥글에 텍스트를 추가하려면
다음 코드 예제에서는 문서에서 각 섹션의 기본 바닥글에 삽입될 텍스트의 글꼴을 설정하고 텍스트를 바닥글에 삽입합니다.
For Each section As Word.Section In Me.Sections Dim footerRange As Word.Range = section.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed footerRange.Font.Size = 20 footerRange.Text = "Confidential" Next
foreach (Word.Section wordSection in this.Sections) { Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed; footerRange.Font.Size = 20; footerRange.Text = "Confidential"; }
문서의 머리글에 텍스트를 추가하려면
다음 코드 예제에서는 문서의 각 머리글에 페이지 번호를 표시할 필드를 추가하고, 텍스트가 머리글의 오른쪽에 정렬되도록 단락 맞춤을 설정합니다.
For Each section As Word.Section In Me.Sections Dim headerRange As Word.Range = section.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage) headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight Next
foreach (Word.Section section in this.Sections) { Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage); headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; }
응용 프로그램 수준 추가 기능
다음 코드 예제를 사용하려면 프로젝트의 ThisAddIn 클래스에서 코드 예제를 실행하십시오.
문서의 바닥글에 텍스트를 추가하려면
다음 코드 예제에서는 문서에서 각 섹션의 기본 바닥글에 삽입될 텍스트의 글꼴을 설정하고 텍스트를 바닥글에 삽입합니다.이 코드 예제에서는 활성 문서를 사용합니다.
For Each section As Word.Section In Me.Application.ActiveDocument.Sections Dim footerRange As Word.Range = section.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed footerRange.Font.Size = 20 footerRange.Text = "Confidential" Next
foreach (Word.Section wordSection in this.Application.ActiveDocument.Sections) { Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed; footerRange.Font.Size = 20; footerRange.Text = "Confidential"; }
문서의 머리글에 텍스트를 추가하려면
다음 코드 예제에서는 문서의 각 머리글에 페이지 번호를 표시할 필드를 추가하고, 텍스트가 머리글의 오른쪽에 정렬되도록 단락 맞춤을 설정합니다.이 코드 예제에서는 활성 문서를 사용합니다.
For Each section As Word.Section In Me.Application.ActiveDocument.Sections Dim headerRange As Word.Range = section.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage) headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight Next
foreach (Word.Section section in this.Application.ActiveDocument.Sections) { Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage); headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; }