Setting System.Drawing.Color through .NET COM Interop

Posted by Maxim on Stack Overflow See other posts from Stack Overflow or by Maxim
Published on 2010-05-29T10:23:00Z Indexed on 2010/05/29 12:52 UTC
Read the original article Hit count: 501

Filed under:
|
|
|
|

I am trying to use Aspose.Words library through COM Interop. There is one critical problem: I cannot set color. It is supposed to work by assigning to DocumentBuilder.Font.Color, but when I try to do it I get OLE error 0x80131509. My problem is pretty much like this one: http://bit.ly/cuvWfc

update:

Code Sample:

from win32com.client import Dispatch
Doc = Dispatch("Aspose.Words.Document")
Builder = Dispatch("Aspose.Words.DocumentBuilder")
Builder.Document = Doc
print Builder.Font.Size
print Builder.Font.Color

Result:

12.0
Traceback (most recent call last):
  File "aaa.py", line 6, in <module>
    print Builder.Font.Color
  File "D:\Python26\lib\site-packages\win32com\client\dynamic.py", line 501, in __getattr__
    ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2146233079, 'OLE error 0x80131509', None, None)

Using something like Font.Color = 0xff0000 fails with same error message

While this code works ok:

using Aspose.Words;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.Font.Color = System.Drawing.Color.Blue;
            builder.Write("aaa");
            doc.Save("c:\\1.doc");
        }
    }
}

So it looks like COM Interop problem.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET