コード例 #1
0
def main():
    hr, rpc = createWpsRpcInstance()
    if FAILED(hr):
        print("createWpsRpcInstance failed with hr: ", hr)
        sys.exit(-1)

    app = RpcProxy(rpc.getWpsApplication())
    print(app.last_error)

    # get the raw object
    obj = app.rpc_object
    print(obj)

    print(app.Build)
    app.Visible = False
    app.Visible = True

    doc = app.Documents.Add()
    print(doc.Name)

    if not app.Selection.InsertAfter("Hello, world"):
        print("Can't insert text")

    font = app.Selection.Font
    font.Bold = True

    doc.Close(SaveChanges=wpsapi.wdDoNotSaveChanges)

    try:
        # should be failed since no Documents opened.
        doc = app.ActiveDocument
    except Exception as e:
        print(e)

    app.Quit(wpsapi.wdDoNotSaveChanges)
コード例 #2
0
def convert_to(paths, format, abort_on_fails=False):
    hr, rpc = createWpsRpcInstance()
    if hr != S_OK:
        raise ConvertException("Can't create the rpc instance", hr)

    app = RpcProxy(rpc.getWpsApplication(), True)

    # we don't need the gui
    app.Visible = False

    docs = app.Documents
    docs.use_exception = abort_on_fails

    for path in paths:
        abs_path = os.path.realpath(path)
        if os.path.isdir(abs_path):
            files = [(os.path.join(abs_path, f)) for f in os.listdir(abs_path)]
            for file in files:
                convert_file(file, docs, format)
        else:
            convert_file(abs_path, docs, format)

    app.Quit()