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/.

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


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.0.1.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywpsrpc-1.0.1-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.5+CPython 3.6+CPython 3.7+CPython 3.8+

File details

Details for the file pywpsrpc-1.0.1.tar.gz.

File metadata

  • Download URL: pywpsrpc-1.0.1.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

File hashes

Hashes for pywpsrpc-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4f2197cbd908c075f6bac5ce4fe6346b55d9c411f3d1f2d757c3aa059efff7ff
MD5 bba84671556a6ba74fa78e652c82da93
BLAKE2b-256 4c14cf6cfbb2f98ffd5891c8899f1f35fef7bc0b86524b8d66eb9953be1817f5

See more details on using hashes here.

File details

Details for the file pywpsrpc-1.0.1-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl.

File metadata

  • Download URL: pywpsrpc-1.0.1-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl
  • Upload date:
  • Size: 4.8 MB
  • Tags: CPython 3.5+, CPython 3.6+, CPython 3.7+, CPython 3.8+
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

File hashes

Hashes for pywpsrpc-1.0.1-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 99bc5794d00e5afe7b9748d2f3b8943a142a3e17f03bc8176d4c5115a9a8db6a
MD5 893b353a029ae35233f0609c7e4a84f1
BLAKE2b-256 b435b14f5467c92fc2445deeaea68cf1295c16431c97edea768666e15ab1837b

See more details on using hashes here.

Supported by

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