Tôi nhìn here và here và hereLàm thế nào để thêm một "Trang x của y" chân để Word2007 doc như tôi đang tạo ra nó bằng cách sử C#
Tôi cố gắng này:
private void AddFooters()
{
foreach (Word.Section wordSection in this.WordDoc.Sections)
{
object fieldEmpty = Word.WdFieldType.wdFieldEmpty;
object autoText = "AUTOTEXT \"Page X of Y\" ";
object preserveFormatting = true;
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Add(
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range,
ref fieldEmpty, ref autoText, ref preserveFormatting);
}
}
Và đây:
private void AddFooters()
{
foreach (Word.Section section in this.WordDoc.Sections)
{
Word.Range footerRange = section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
this.WordDoc.ActiveWindow.Selection.TypeText("Page ");
footerRange.Fields.Add(footerRange, Word.WdFieldType.wdFieldPage);
this.WordDoc.ActiveWindow.Selection.TypeText(" of ");
footerRange = section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
footerRange.Fields.Add(footerRange, Word.WdFieldType.wdFieldNumPages);
footerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
}
}
Tôi đã ghi macro VBA này, nhưng dường như không hữu ích.
Sub Macro1()
'
' Macro1 Macro
'
'
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Bold Numbers 3"). _
Insert Where:=Selection.Range, RichText:=True
End Sub
Không có gì mà tôi đã thử hoàn toàn làm việc cho tôi hoàn toàn (tôi đã phần nào đóng). Hãy cho tôi biết nếu có điều gì đó về câu hỏi không rõ ràng.
Bạn đã bao giờ làm việc đó chưa? Tôi đang tìm cách làm điều tương tự. –
@Christopher Mahan, xin lỗi, tôi đã ngừng thử một lúc nào đó và quyết định phát ra mã LaTeX và biên dịch thay vào đó. Đó là đủ tốt cho tôi. Nếu bạn giải quyết vấn đề này, tôi sẽ sẵn sàng xem câu trả lời. Tôi có thể đề nghị đốt cháy một số danh tiếng của bạn trên tiền thưởng. Đặt nó cao nhưng giải thích những gì bạn cần. –