我正在用C#编写一个Office外接程序.我正试图从带有的Word文档中获取没有空格的字符的数量。但是,到long的转换不起作用。
错误信息是:
"System._ComObject“类型的COM对象不能转换为"System.IConvertible”
到目前为止,下面是我的thisAddIn.cs代码片段:
using Word = Microsoft.Office.Interop.Word;
// ...
public partial class ThisAddIn
{
public void Calc()
{
Word.Document doc = this.Application.ActiveDocument ;
long c=doc.BuiltInDocumentProperties[Word.WdBuiltInProperty.wdPropertyCharacters];
// ^^^ Error ^^^
}
}问题:
和/或
发布于 2018-10-26 15:57:32
int c = doc.BuiltInDocumentProperties[Word.WdBuiltInProperty.wdPropertyCharacters].Value;BuiltInDocumentProperties[]的结果是Office.DocumentProperty (可以通过检查Word VBA编辑器中的局部变量窗口找到),它的默认.Value属性包含数字。
它在VBA中不使用.Value,因为VBA具有不同的默认值赋值(Let),以及与Set分离的对象引用赋值。另外,VBA中的Long类型是.NET中的Int32类型。
https://stackoverflow.com/questions/33419199
复制相似问题