com - WdInformation.wdVerticalPositionRelativeToPage 在 VBA 和 C# 中给出不同的值
问题描述
我正在使用 Microsoft.Office.Interop.Word 将一段用 VBA 编写的代码翻译成 C# 我观察到,
在 C# 中,与在其中p是 Paragraph 对象p.Range.Information[WdInformation.wdVerticalPositionRelativeToPage]
的 VBA 中使用时相比,它给出了不同的值
。p.Range.Information(wdVerticalPositionRelativeToPage)
每当 Word 文档页面上出现形状时,就会发生这种情况。我想知道为什么会这样?当通过 C# 与 VBA 打开文档时,文档的呈现有什么不同吗?
PS - 在这两种情况下,单词可见性都设置为 false。
编辑:更新 - 我尝试将可见性设置为 true,并且在使用 C# 与使用 VBA 启动 Document 时,我确实观察到文档呈现的差异。我该如何解决?
解决方案
So I figured out the problem. My code was trying to access header section like this
foreach (Section sect in objDoc.Sections)
{
foreach (HeaderFooter hf in sect.Headers)
{
someFunction(hf.Range.Paragraphs, false, false);
if (hf.Shapes.Count > 0) // to handle shapes in Headers
{
someFunction(hf.Shapes);
}
}
}
For some reason, accessing headers changes the position of paragraphs in rendering causing the different values. To fix this, I now access headers as the last piece in my code. Hope this helps somebody.
推荐阅读
- variables - 将随机选择字符串保存到ansible中的可用变量
- r - 使用 dplyr 在 R 中排序:如何根据另一列中的类别总和在一列中按类别排序?
- hapijs - 使用 Hapi 18.1 延迟响应
- excel - 我可以使用相对引用自动填充表格新列中的公式吗
- ios - UIBezierPath 动画从圆形到圆角方形
- tensorflow - 未找到张量板
- html - 如何使用 CSS html 定位背景
- angular - Angular 订阅未按预期运行 - 数组为空
- c++ - 使用 Bazel 在 macOS 应用程序中构建 OpenCV(.dylib 与 .a 文件)
- excel - 解决 VBA 崩溃后的运行时错误“91”,该错误在崩溃前找到