Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition出现C#编译器错误;

我们的香蕉人

我有以下代码,用于在运行时修改Word文档中的文本框架。

这是在.NET Windows Forms应用程序中。

var oShapes = oWord.ActiveDocument.Shapes; 
var titleShape = oShapes["Title"];

var myWord = new Microsoft.Office.Interop.Word.Application();

titleShape.Height = myWord.InchesToPoints(1.75F);
titleShape.Width = myWord.InchesToPoints(0.45F);
titleShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition;
titleShape.RelativeVerticalPosition =  Microsoft.Office.Interop.Word.WdRelativeVerticalPosition();
titleShape.Left = 4.35F;
titleShape.Top = 17.5F;
titleShape.TextFrame.WordWrap = 0;
titleShape.LockAnchor = 1;

var sTitle =string.Empty;

titleShape.TextFrame.TextRange.Text = DocumentType; // sTitle;
titleShape.TextFrame.AutoSize=-1;

不幸的是,我一定弄错了,因为Microsoft.Office.Interop.Word.WdRelativeHorizo​​ntalPosition; 在VS 2010中(以及下面的行中)显示为错误。

通过Office Interop使用像c#这样的单词枚举常量的正确方法是什么?

我们的香蕉人

我找到了它,我在调用枚举名称,而不是枚举常量。

所以 Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition

应该

Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;

(再加上我使用方括号认为是问题所在)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

C# Microsoft.Office.Interop.Word 保护段落

使用参考C#添加Microsoft.Office.InterOp.Word

Microsoft.Office.Interop.Word OMath

Microsoft.Office.Interop.Word - Word 在尝试打开文件时遇到错误

如何使用 Microsoft.Office.Interop.Word 在 C# 中编辑 docx 文件

Microsoft.Office.Interop.Word:在C#中为图像添加标题

带有C#的Microsoft.Office.Interop.Word-标识现有目录对象

C#Microsoft.Office.Interop.Word SpellingChecked不返回真实值

在VBScript中使用Microsoft.Office.Interop.Word枚举常量

使用Microsoft.Office.Interop Word和Excel

使用f#Microsoft.Office.Interop.Word搜索和替换

Microsoft.Interop.Office.Word完整样式不适用

使用Microsoft.Office.Interop.Word启用内置的Microsoft Word按钮控件

C#-Microsoft.Office.Interop.Excel.Sheets到Microsoft.Office.Interop.Excel.Worksheet []

C# Microsoft.Office.Interop.Word 替换为 Selection.Find.Execute() 超过第一个单词

机器中的单独Microsoft.Office.Interop.Word实例和Word应用程序

是否可以使用Microsoft.Office.Interop.Word以编程方式从Word文档中删除行号?

如何通过 Microsoft.Office.Interop.Word 在 wdRevisionsViewFinal 中将 word 转换为 html?

C#使用Microsoft.Office.Interop.Excel读取数据

确定是否选中了word文档中的复选框 - c#中的char u0015、microsoft.office.interop.word

Microsoft.Office.Interop.Excel读取错误的颜色?

Office 2007的Microsoft.Office.Interop.Excel

C#-TableOfContent条目的Office Interop Word格式缩进

无法使用microsoft.office.interop.word在当前一字之后插入图像

可以将DebuggerDisplay属性应用于Microsoft.Office.Interop.Word.Range吗?

我如何创建接口Microsoft.Office.Interop.Word.Application的新实例

Microsoft.Office.Interop.Word中仅可访问的第一页

在哪里可以找到Microsoft.Office.Interop.Word.dll(2010)?

如何使用Microsoft.Office.Interop.Word库删除输出中的段落间距