Ms word 如何添加“侧”页眉或页脚,并使用VSC将其与word插件垂直对齐?

Ms word 如何添加“侧”页眉或页脚,并使用VSC将其与word插件垂直对齐?,ms-word,vsto,office-interop,office-addins,Ms Word,Vsto,Office Interop,Office Addins,我想插入页眉或页脚,并通过C使用word addin vsto将其垂直对齐到页面的侧面。下面是我希望看到的最终结果示例。我试图研究这个问题,但找不到一个例子,说明有人用编程的方式做这件事?有人知道如何做到这一点吗 所以现在我正在插入一个文本框,我可以像这样将它与页面的侧面对齐,但我不希望我的最终用户能够选择或删除它。所以我认为解决办法是把它放在一个侧面页眉或页脚。。。但现在的问题是如何实现相同的对齐和定位?所以回答我自己的问题。您可以从当前活动文档中获取标题,尽管标题看起来仅位于顶部,但实际上它

我想插入页眉或页脚,并通过C使用word addin vsto将其垂直对齐到页面的侧面。下面是我希望看到的最终结果示例。我试图研究这个问题,但找不到一个例子,说明有人用编程的方式做这件事?有人知道如何做到这一点吗


所以现在我正在插入一个文本框,我可以像这样将它与页面的侧面对齐,但我不希望我的最终用户能够选择或删除它。所以我认为解决办法是把它放在一个侧面页眉或页脚。。。但现在的问题是如何实现相同的对齐和定位?

所以回答我自己的问题。您可以从当前活动文档中获取标题,尽管标题看起来仅位于顶部,但实际上它跨越了整个文档,可以容纳adobe photo shop中的任何层。无论如何,要插入此标题层并垂直对齐文本框,可以通过以下方法实现:

//note: we are in ThisAddin.cs (word addin) and this.Application = word addin

private void drawTdCycleTextBox(String cycleCode)
        {
            int length = 1000;

            // get the current cursor location
            Range cursorRange = this.Application.Selection.Range;

            // get the primary header on the current page
            HeaderFooter header = this.Application.ActiveDocument.Sections.First.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
            // header.Range.Text = "THIS IS A TEST";

            // create the textbox inside the header and at the current cursor location
            Microsoft.Office.Interop.Word.Shape textBox = header.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationUpward, 0, 0, 35, length, cursorRange);
            textBox.TextFrame.TextRange.Font.Size = 20;
            textBox.TextFrame.TextRange.Text = Util.repeatedTextOutput(cycleCode, 25, length);
            textBox.Fill.ForeColor.RGB = ColorTranslator.ToOle(Color.Turquoise);
            textBox.Fill.Transparency = .35F;
        }