c# - Range.Information 不工作 C#

标签 c# vb.net range

我目前正在修复 C# 代码从 Visual Basic 转换后出现的错误。在我的 C# 代码中,我有以下内容:

Pos = oWord.InchesToPoints(7);
oDoc.Bookmarks["\\endofdoc"].Range.InsertParagraphAfter();
do
{
    oRng = oDoc.Bookmarks["\\endofdoc"].Range;
    oRng.ParagraphFormat.SpaceAfter = 6;
    oRng.InsertAfter("");
    oRng.InsertParagraphAfter();
} while (Pos >= oRng.Information(WdInformation.wdVerticalPositionRelativeToPage));

我遇到的问题是这部分:

oRng.Information(WdInformation.wdVerticalPositionRelativeToPage)

我遇到错误“索引属性‘Microsoft.Office.Interop.Word.Range.Information’具有必须提供的非可选参数。”

根据 msdn,参数的类型必须是 WdInformation。我仔细检查了一下,wdVerticalPositionRelativeToPage 就是那种类型。我究竟做错了什么?任何帮助将不胜感激。

如果有帮助,下面是转换前 VB 中的相同代码:

Pos = oWord.InchesToPoints(7)
oDoc.Bookmarks.Item("\endofdoc").Range.InsertParagraphAfter()
    Do
        oRng = oDoc.Bookmarks.Item("\endofdoc").Range
        oRng.ParagraphFormat.SpaceAfter = 6
        oRng.InsertAfter("")
        oRng.InsertParagraphAfter()
    Loop While Pos >= oRng.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)

最佳答案

错误消息明确指出 Range.Information 是索引器。

使用这个语法:

oRng.Information[WdInformation.wdVerticalPositionRelativeToPage];

关于c# - Range.Information 不工作 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27026729/

相关文章:

C# : Console. Read() 未获取 "right"输入

vb.net - 为什么我无法检查 'DateTime' 是否为 'Nothing' ?

vb.net - 使用 Visual Studio 代码,编码 vb.net,如何启动我的程序然后进入 Debug模式?

python - Chaco:从 chaco 图中获取索引和值

javascript - 如何使用 jQuery 在客户端的 HTML 表中显示图像

c# - 从对象填充 TreeView

c# - 如何在对象上进行交易

c# - 从 C# 到 VB 中的 where 继承

mysql - SQL Update + Inner Join 一系列行

android - RxJava/RxAndroid : continue range loop after error