【问题标题】:VSTO Word 2013 - How to align string in footerVSTO Word 2013 - 如何在页脚中对齐字符串
【发布时间】:2016-08-04 15:32:13
【问题描述】:

我创建了一个应用程序,当按下按钮时,它会在文档的页脚中放置一段指定的文本。

问题是我希望这个字符串总是出现在页脚的顶行,与右侧对齐。

有没有办法对齐页脚中的一段文本,使其始终显示在页脚的右上角?

【问题讨论】:

    标签: c# vsto add-in word-addins


    【解决方案1】:

    好吧,让我说,这将需要更多研究如何获得正确的位置,并且可能需要进行一些硬编码的调整。以这段代码为起点

    你需要解决很多问题,比如 您真的只想使用第 1 节吗? 您真的只想使用主页脚吗? PageSetup 是否足以获得正确的位置?

    也行

    shp.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionBottomMarginArea;
    

    似乎没有任何影响,但您可以通过 Word UI 进行设置。这将有助于更详细地探索,因为它可以为您节省大量计算

    using System;
    using Word = Microsoft.Office.Interop.Word;
    
    namespace WordAddIn1
    {
        public class Class1
        {
            public void InsertShape(Word.Document doc)
            {
                try
                {
                    Word.Section sec = doc.Sections[1];
                    Word.HeaderFooter foo = sec.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
    
                    Word.Range rng = foo.Range;
    
                    float leftPos = doc.PageSetup.PageWidth - doc.PageSetup.RightMargin;
                    float topPos = doc.PageSetup.PageHeight - doc.PageSetup.BottomMargin;
    
                    Word.Shape shp = doc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
                                                           leftPos, topPos, 50, 20, rng);
    
                    shp.TextFrame.TextRange.Text = "Text";
                    shp.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionBottomMarginArea;
    
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-02-06
      • 2020-02-04
      • 1970-01-01
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 2015-10-13
      • 2021-02-02
      • 2020-12-03
      相关资源
      最近更新 更多