Python bindings for the WPS Office RPC
Project description
pywpsrpc
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/.
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 failes
# 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._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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pywpsrpc-1.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb7f7b739730bc327402106fc238c2dac3f74e472b347f73620ec56ba331ab2e |
|
MD5 | 4ec358442d884801a92208554787cbe6 |
|
BLAKE2b-256 | 12dd096e507766f0554e33d71d0deb41c6f2718d835a8f702a95533f9b58f7f5 |
Hashes for pywpsrpc-1.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 761a7bb23224631fddbc112f4154b4c3f899c8aa0e64a269f827a094a4d36f6e |
|
MD5 | 00d114610c2b42730b0262912a57531b |
|
BLAKE2b-256 | 930fcba605f8c21ad9f85af59a297250f39a5c297d39f826be6e4c60681ff2d1 |
Hashes for pywpsrpc-1.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24db038c588ae3b6a72a4a0bd84951853bc7e6badf37f4560b267c8dcc8f2b32 |
|
MD5 | 309300f3b455e9eca8668d96b55b2e8f |
|
BLAKE2b-256 | ac578c95670784d2a7be5e19dc2b43ef2a003fc1439971497a2838c9476bd5f4 |
Hashes for pywpsrpc-1.0.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e73a7376b41d587454a279a5370203e3738c4b5a1c7fe860b1e09253987d0987 |
|
MD5 | 51b3d978fb4f98ed289656a75eb93f4e |
|
BLAKE2b-256 | 53aa0c2298bc73afeeab14a9b91095d5e87330ca13fc89842d153d16ee13e00b |