Skip to main content

Python bindings for the WPS Office RPC

Project description

pywpsrpc

Build Status PyPI version Python version License: MIT

Python bindings for WPS Office RPC (for Linux version only).

What is WPS Office RPC?

To make it simple, it means you can use the rpc (api) get working with WPS Office, open, edit and save documents, extend the WPS Office functionals etc.

The C++ SDK headers was taken from wps_cpp with no changes:

Copyright @ 2012-2019, Kingsoft office,All rights reserved.

For full API references, go to https://open.wps.cn/docs/office or https://docs.microsoft.com/en-us/office/vba/api/overview/.

For pywpsrpc document, go to the wiki page.

Requirements

  • Python 3.5+
  • Qt5 (the SDK required both for building & running)
  • WPS Office for Linux 11.1.0.9080+
  • sip 5.0+ (for building)
  • qmake (for building)
  • gcc (for building)

How to build

Run sip-build under the project root directory

append --verbose for getting the progress of building

Installation

The pywpsrpc can be installed from PyPi:

pip install pywpsrpc

You can also install from the source:

# the easy way, you may need the root privilege
sip-install

# or package first, and then install the whl by pip
sip-wheel

Quick Start

# First import the module you want
# rpcwpsapi contains the interfaces for WPS
# rpcwppapi is for WPP
# and rpcetapi for ET
# the common module contains the shared interfaces, you can not use it alone.

# you always need the createXXXRpcInstance, so first import
# take wps for example here
from pywpsrpc.rpcwpsapi import (createWpsRpcInstance, wpsapi)

# use the RpcProxy to make things easy...
from pywpsrpc import RpcProxy

# now create the rpc instance
hr, rpc = createWpsRpcInstance()

# all the calls returns the error code as the first value
# you can check it for fails
# 0 means all fines, you can use the common module's S_OK,
# FAILED or SUCCEEDED to check
# recommend use the RpcProxy instead

# get the application and you get everything...
# here we use the RpcProxy to wrap the application
# otherwise, you have to call Release on each instance
# and handle the hr for every call...
app = RpcProxy(rpc.getWpsApplication())

# Add blank doc e.g.
doc = app.Documents.Add()

# append text...
selection = app.Selection
selection.InsertAfter("Hello, world")

# bold the "Hello, world"
selection.Font.Bold = True

# get a notify about saving
rpc.registerEvent(app.rpc_object,
                  wpsapi.DIID_ApplicationEvents4,
                  "DocumentBeforeSave",
                  onDocumentBeforeSave)

def onDocumentBeforeSave(doc, saveAsUi, cancel):
    # to discard the saving, return cancel as True
    return saveAsUi, cancel

# save the doc, onDocumentBeforeSave will be called
doc.SaveAs2("test.docx")

# Quit the application if you don't need anymore
# use wpsapi.wdDoNotSaveChanges to ignore the changes
app.Quit(wpsapi.wdDoNotSaveChanges)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywpsrpc-1.1.0.tar.gz (1.7 MB view hashes)

Uploaded Source

Built Distributions

pywpsrpc-1.1.0-cp38-cp38-manylinux1_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.8

pywpsrpc-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.7m

pywpsrpc-1.1.0-cp36-cp36m-manylinux1_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.6m

pywpsrpc-1.1.0-cp35-cp35m-manylinux1_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.5m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page