0
, 에서 C# 프로그래밍하여 Word 파일에 헤더를 삽입하는 방법 지금은 내 질문은 : 내가 경로 을 선택하여 워드 파일의 헤더를 설정하는 방법 또한 Microsoft.Office.Interop.Word.Section section
을 시도했지만이있다 새로운 create 파일.내가 OpenFileDialog를 컨트롤에서 워드 파일을 선택하고의 WinForm
내 코드 :
public void addheader()
{
string temp_path = textbox1.text
foreach (Microsoft.Office.Interop.Word.Section section in temp_path.Sections)
{
//Get the header range and add the header details.
Microsoft.Office.Interop.Word.Range headerRange = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
headerRange.Fields.Add(headerRange, Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage);
headerRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
headerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdBlue;
headerRange.Font.Size = 10;
headerRange.Text = "Header text goes here";
}
}
워드 파일의 경로로 헤더를 설정하는 방법은 없나요? 샘플 시도
열기 단어, 코드를 볼 녹화하려면 Alt + F11을 중지 수동으로 물건을, 매크로 기록을 시작하고 볼 수 있습니다 당신이 사용해야하는 방법. –
@Alex 감사하지만 프로그래밍으로해야합니다. – Mamta
예. 그러나 기록 된 VBA 코드를 보면 헤더를 추가하고 편집하는 데 사용되는 개체 메서드를 볼 수 있으므로 C#에서 해당 코드를 복제 할 수 있습니다. –