I am writing an Office Add-In in C#.
I am trying to get the number of characters without spaces from a Word document with the WdBuiltInProperty
. However, the conversion to long
does not work.
The error message is:
The COM Object of Type "System._ComObject" can not be converted to "System.IConvertible"
Here is my code snippet of thisAddIn.cs
so far:
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 ^^^
}
}
Questions:
- How can the conversion be done properly?
and/or
- Is there another way to get the number of characters without spaces ?