我在 Word 文档的页脚中有一个文本框。它有一些左对齐的模板文本,然后已经有“第 x 页,共 n 页”右对齐。当我尝试替换模板文本时,所有文本都被替换了。
使用 C# 或 VB(无论哪种方式)我需要替换文本框内的文本(所有这些文本都应该左对齐),然后添加“Page x of n”(右对齐)。
这是我迄今为止的测试:
string footer;
foreach (Shape shape in oMyDoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes)
{
footer = shape.TextFrame.ContainingRange.Text;
footer = footer.Replace("\r", "");
footer = footer.Replace("[Quote Type]", "Big Quote");
footer = footer.Replace("(", "\u2022");
int start = footer.IndexOf("Pager ");
footer = footer.Remove(start + 5);
var numPages = oMyDoc.ComputeStatistics(WdStatistic.wdStatisticPages);
footer = footer + " of " + numPages.ToString();
shape.TextFrame.ContainingRange.Text = footer;
}