Skip to main content

Python bindings for the WPS Office RPC

Project description

pywpsrpc

Build Status PyPI version Python version License: MIT

WPS Office for Linux二次开发C++接口Python绑定.

Read this in other languages: English

WPS Office二次开发接口

WPS二次开发接口允许开发者通过给定的接口来调起WPS并执行指定的任务, 比如你可以打开、编辑然后保存文档,转换文档格式等文档自动化操作,又或者将WPS嵌入到自己的程序、进行功能扩展等。

关于详细的接口文档,可参考

对于pywpsrpc本身的文档,可跳转到wiki查看。

依赖

  • Python 3.6+
  • Qt5 (C++ SDK依赖)
  • WPS Office for Linux 11.1.0.9080+
  • sip 6.0+ (仅编译)
  • qmake (仅编译)
  • g++ (仅编译)
  • 桌面环境(WPS运行需要)

PS,目前WPS整合模式有BUG,非把WPS嵌入到自己进程的场景建议先切换到多组件模式

如何编译

在项目顶层目录下运行终端执行: sip-build

如果需要查看编译相关输出信息,可添加 --verbose 选项

安装

建议通过PyPi安装:

pip install pywpsrpc

如果默认的源太慢,建议自行搜索添加中国pip源

通过源码编译安装:

先打包执行: sip-wheel

打包完成后再通过pip install pywpsrpc-*.whl命令安装

快速上手

# 第一步先import所需模块(rpcxxxapi,xxx为对应项目的名字)
# rpcwpsapi模块为WPS文字项目的开发接口
# rpcwppapi则是WPS演示的
# rpcetapi毫无疑问就是WPS表格的了
# 另外还有common模块,为前三者的公共接口模块,通常不能单独使用

# 调起WPS必需通过createXXXRpcInstance接口,所以导入它是必需的
# 以WPS文字为例
from pywpsrpc.rpcwpsapi import (createWpsRpcInstance, wpsapi)
from pywpsrpc import RpcIter


# 这里仅创建RPC实例
hr, rpc = createWpsRpcInstance()

# 注意:
# WPS开发接口的返回值第一个总是HRESULT(无返回值的除外)
# 通常不为0的都认为是调用失败(0 == common.S_OK)
# 可以使用common模块里的FAILED或者SUCCEEDED去判断

# 通过rpc实例调起WPS进程
hr, app = rpc.getWpsApplication()

# 比如添加一个空白文档
hr, doc = app.Documents.Add()

# 加点文字
selection = app.Selection
selection.InsertAfter("Hello, world")

# 将前面插入的"Hello, world"加粗
selection.Font.Bold = True

# 光标移到末尾
selection.EndKey()

# 再插入空段
selection.InsertParagraph()

# 光标移到新段
selection.MoveDown()

# 再码些文字
selection.TypeText("pywpsrpc~")

# 使用RpcIter遍历所有段
paras = doc.Paragraphs
for para in RpcIter(paras):
    print(para.Range.Text)

# 或者通过索引方式
for i in range(0, paras.Count):
    # 注意:首个元素总是从1开始
    print(paras[i + 1].OutlineLevel)

def onDocumentBeforeSave(doc):
    # 如果想取消当前文档保存,第二个返回值设为True
    print("onDocumentBeforeSave called for doc: ", doc.Name)
    # SaveAsUI, Cancel
    return True, False

# 注册文档保存前通知
rpc.registerEvent(app,
                  wpsapi.DIID_ApplicationEvents4,
                  "DocumentBeforeSave",
                  onDocumentBeforeSave)

# 保存文档, onDocumentBeforeSave会被调用到
doc.SaveAs2("test.docx")

# 退出WPS进程
# 使用wpsapi.wdDoNotSaveChanges来忽略文档改动
app.Quit(wpsapi.wdDoNotSaveChanges)

例子

文档互转

嵌入

WPS嵌入第三方进程窗口

在服务器上运行

点我查看

关于授权

pywpsrpc为MIT开源授权协议,项目本身允许商用,但前提是你所使用的WPS Office For Linux版本允许商用(目前个人版本即社区版本不允许),具体需要联系WPS官方咨询。对于不在合理范围使用本项目的,本项目不承担任何法律责任。

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

Uploaded Source

Built Distributions

pywpsrpc-2.3.9-cp313-cp313-manylinux_2_5_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.5+ x86-64

pywpsrpc-2.3.9-cp312-cp312-manylinux_2_5_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.5+ x86-64

pywpsrpc-2.3.9-cp311-cp311-manylinux_2_5_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.5+ x86-64

pywpsrpc-2.3.9-cp310-cp310-manylinux_2_5_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.5+ x86-64

pywpsrpc-2.3.9-cp39-cp39-manylinux_2_5_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

pywpsrpc-2.3.9-cp38-cp38-manylinux_2_5_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.5+ x86-64

pywpsrpc-2.3.9-cp37-cp37m-manylinux_2_5_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.5+ x86-64

pywpsrpc-2.3.9-cp37-cp37m-manylinux1_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.7m

pywpsrpc-2.3.9-cp36-cp36m-manylinux1_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.6m

File details

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

File metadata

  • Download URL: pywpsrpc-2.3.9.tar.gz
  • Upload date:
  • Size: 6.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for pywpsrpc-2.3.9.tar.gz
Algorithm Hash digest
SHA256 4b581abc5689943d63a892fea9e8488ed729c8f6f0e3a324eefbd081d250f993
MD5 621d64571dac4b7ea1d80acc479626d8
BLAKE2b-256 9781a1bda13f7460e8f7c1a83d9cd662bfe56869007364d73b01aaabc94ca66a

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp313-cp313-manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp313-cp313-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 037b915149a51b3ebc69d053664602ce5b8019184a847a3f50dabb293b286bcc
MD5 50511644461722480aad37f807793b30
BLAKE2b-256 bbdfaad04018ef54c110f36e0eb498f8f0fd30049bbb0c3a8dca18714884b41d

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp312-cp312-manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp312-cp312-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 aec097325616b78df5578bad769974d91bfe20ac3333c49a5e4ffe2c2bf155cf
MD5 707c25d28291c86ae91c29eaf6caedec
BLAKE2b-256 781f5b7d673950c99ad6dd8f7e5aa4cfcf113cc74e9555ca4c1d584d2ca719fc

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp311-cp311-manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp311-cp311-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 125bbb2299b04854a47d922eacead9c88e1b4b24d47b2284ad616dfb11b98d5e
MD5 5f9c89237a3696e0ccafea4b45101b93
BLAKE2b-256 a1c698e73a758791e05371e2c36a9ed1a13b99b24e16333b789017cf53d8ae7a

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp310-cp310-manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp310-cp310-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 74e44f775cfc5db1065539280cd63a5465bef68020ac3e23e4fe9398887d7929
MD5 6230eddcc0e5c5bc9b6eec97c5efbf7f
BLAKE2b-256 5c1faf37553e61d47f36b29ff9cf898f788d1492eab72ed5ae1d8c246490fb59

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp39-cp39-manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp39-cp39-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 76a3d10c12beeca65f5a4a13b536638a876751822ede5d651ca1bd00117446e3
MD5 36655952436813f1b2c6ddbeb441de3c
BLAKE2b-256 abf3334360b1896b1f866d96f2c4e515ab82b805c60709d76146ea2cb5ea15bb

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp38-cp38-manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp38-cp38-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 b0bf9d3692995acdbd94213b2519b8e9aef07bc7d2e854ae45e202590058c9cb
MD5 d1fcb2e41c61687c24b80ec2fca326d0
BLAKE2b-256 17118a5ddf7a2542194a70b1d016a1537bb0f82ebd155e7024861e509ae37f1d

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp37-cp37m-manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp37-cp37m-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 6341e06e71d76f171054c5cc07b53c0034e2128e3f38994afec3d41ddac435de
MD5 703fa237e927217aea28da38a13f5ebc
BLAKE2b-256 bb166941fdc0229efd678715b3032a7108e3c4c9bf65ccc0bb182a6202c189a9

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pywpsrpc-2.3.9-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ec247f50fb6dde9e54a124f9d039b6ffee563134e6e121fc2cccb7c3e6248eae
MD5 f8fa320d08cd9dcbe450ad9101cafd05
BLAKE2b-256 d3e29d3cc9a6aeb3db3c6f60cc6a71b1158eab92ba220afb347bbfb51debbf0d

See more details on using hashes here.

File details

Details for the file pywpsrpc-2.3.9-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pywpsrpc-2.3.9-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 7.9 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for pywpsrpc-2.3.9-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9ccac831932aeeb9c3cc0d861db70afc845f351fca1ba43b522e5b7e443e6858
MD5 1be35eab5b01bf14c98023808ae43200
BLAKE2b-256 0fb22709bdc9e2d5c55618150228154bba79b353edf13395eee0929aa8172bbd

See more details on using hashes here.

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