【问题标题】:Setting System.Drawing.Color through .NET COM Interop通过 .NET COM 互操作设置 System.Drawing.Color
【发布时间】:2011-02-25 10:51:12
【问题描述】:

我正在尝试通过 COM Interop 使用 Aspose.Words 库。有一个关键问题:我无法设置颜色。它应该通过分配给 DocumentBuilder.Font.Color 来工作,但是当我尝试这样做时,我得到 OLE 错误 0x80131509。我的问题很像this one。

更新:

代码示例:

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

结果:

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)

使用 Font.Color = 0xff0000 之类的内容失败并显示相同的错误消息

虽然这段代码可以正常工作:

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");
        }
    }
}

所以看起来像是 COM 互操作问题。

【问题讨论】:

  • 请给我们看一段你在做什么的代码

标签: .net python com interop aspose


【解决方案1】:

请检查此处提供的答案: http://www.aspose.com/community/forums/thread/240901/create-a-pivot-table-from-multiple-data-ranges.aspx 我认为,这种方法应该可以帮助您解决问题。

【讨论】:

  • 谢谢解答。看起来可以使用 .NET Reflection 创建像 SetColor(object, propertyname, color) 这样的通用函数。
猜你喜欢
  • 1970-01-01
  • 2012-06-09
  • 2012-06-15
  • 2010-12-24
  • 1970-01-01
  • 2011-02-21
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
相关资源
最近更新 更多