testMSOffice.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:mac-package-build 作者: persepolisdm 项目源码 文件源码
def TestWord():
    # Try and load the object exposed by Word 8
    # Office 97 - _totally_ different object model!
    try:
        # NOTE - using "client.Dispatch" would return an msword8.py instance!
        print("Starting Word 8 for dynamic test")
        word = win32com.client.dynamic.Dispatch("Word.Application")
        TestWord8(word)

        word = None
        # Now we will test Dispatch without the new "lazy" capabilities
        print("Starting Word 8 for non-lazy dynamic test")
        dispatch = win32com.client.dynamic._GetGoodDispatch("Word.Application")
        typeinfo = dispatch.GetTypeInfo()
        attr = typeinfo.GetTypeAttr()
        olerepr = win32com.client.build.DispatchItem(typeinfo, attr, None, 0)
        word = win32com.client.dynamic.CDispatch(dispatch, olerepr)
        dispatch = typeinfo = attr = olerepr = None
        TestWord8(word)

    except pythoncom.com_error:
        print("Starting Word 7 for dynamic test")
        word = win32com.client.Dispatch("Word.Basic")
        TestWord7(word)

    try:
        print("Starting MSWord for generated test")
        # Typelib, lcid, major and minor for the typelib
        try:
            o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0, bForDemand=1)
        except TypeError:
            o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0)
        if o is None :
            raise ImportError, "Can not load the Word8 typelibrary."
        word = win32com.client.Dispatch("Word.Application.8")
        TestWord8(word)
    except ImportError as details:
        print("Can not test MSWord8 -", details)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号