我正在构建一个Word VSTO(VB.NET)程序,我需要在顶部,左侧,右侧和底部找到形状点的确切位置。我使用以下代码,
objShape = Globals.ThisAddIn.Application.ActiveDocument.Shapes(intShapesLoop)
objShape.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin
objShape.Select()
sngPageWidth = Globals.ThisAddIn.Application.Selection.Range.PageSetup.PageWidth
sngPageHeight = Globals.ThisAddIn.Application.Selection.Range.PageSetup.PageHeight
sngMarginsLeft = objShape.Left + Globals.ThisAddIn.Application.Selection.Range.PageSetup.LeftMargin
sngMarginsRight = sngPageWidth - (objShape.Width + sngMarginsLeft + sngGutterPosistionRight)
这样可以正常工作,并从左侧和右侧显示正确的位置值。但是,我使用下面的代码作为顶部和底部位置,
sngMarginsTop = objShape.Top + Globals.ThisAddIn.Application.Selection.Range.PageSetup.TopMargin
sngMarginsBottom = sngPageHeight - (objShape.Height + sngMarginsTop)
这显示错误的位置值。这是什么问题?从Top值开始,它显示的值比正确值小12点
我发现这只发生在少数文件上。它在大多数文档中显示正确的Top值,但在少数文档中显示错误的Top值。
答案 0 :(得分:1)
这就是顶值错误的原因,
在“高级布局”对话框中( 文字环绕>更多布局选项... ),
由红色矩形标记的组合框必须设置为边距。最高值错误的原因是因为绝对位置......低于设置为段落而不是保证金。当此值设置为保证金时,最高值变为正确。