Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MS Word互操作-访问点方法_C#_.net_Ms Word_Office Interop_Word 2010 - Fatal编程技术网

C# MS Word互操作-访问点方法

C# MS Word互操作-访问点方法,c#,.net,ms-word,office-interop,word-2010,C#,.net,Ms Word,Office Interop,Word 2010,我试图在从c#应用程序打印的Word文档中设置打印边距,但访问需要调用的方法时遇到问题(基于MS Word VBA中的方法) 在VBA中,代码如下所示: Options.printBackground = False With ActiveDocument.PageSetup .TopMargin = CentimetersToPoints(0.61) .BottomMargin = CentimetersToPoints(0.43) .LeftMargin = Cen

我试图在从c#应用程序打印的Word文档中设置打印边距,但访问需要调用的方法时遇到问题(基于MS Word VBA中的方法)

在VBA中,代码如下所示:

Options.printBackground = False

With ActiveDocument.PageSetup
    .TopMargin = CentimetersToPoints(0.61)
    .BottomMargin = CentimetersToPoints(0.43)
    .LeftMargin = CentimetersToPoints(1.27)
    .RightMargin = CentimetersToPoints(0.43)
    .Gutter = CentimetersToPoints(0)
End With
这是我的c代码

我得到的错误是:
非静态字段、方法或属性“Microsoft.Office.Interop.Word.\u Application.cmmstopoints(float)”需要对象引用

在VS2010对象浏览器中搜索厘米点后,我尝试了几个变量

对象浏览器中的可用界面包括:

  • Microsoft.Office.Interop.Word.\u应用程序.cm停止点数(浮点)
  • Microsoft.Office.Interop.Word.ApplicationClass.cm停止点数(浮点)
  • Microsoft.Office.Interop.Word.\u全局.cm停止点数(浮点)
  • Microsoft.Office.Interop.Word.GlobalClass.cm停止点数(浮点)
我如何访问这样的方法


谢谢

如错误消息所示,您需要引用
Word.Application
对象才能访问此方法,因为它不是静态的

我猜您在某个地方有一个
oWordApp
用于创建或打开
oWordDoc
,因此您可以从该对象访问该方法

或者,您可以从
oWordDoc
(Word.Document
)对象检索
Word.Application
的实例

oWordDoc.PageSetup.TopMargin = Microsoft.Office.Interop.Word.Application.CentimetersToPoints(float.Parse ("0.61"))  ;
oWordDoc.PageSetup.TopMargin = oWordDoc.Application.CentimetersToPoints(float.Parse("0.61"));