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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.13manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.9manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.8manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.7m

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

Uploaded CPython 3.6m

File details

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

File metadata

  • Download URL: pywpsrpc-2.3.12.tar.gz
  • Upload date:
  • Size: 6.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pywpsrpc-2.3.12.tar.gz
Algorithm Hash digest
SHA256 787441dea98b09f1b34eec38ebb8d340dfb244f5e73191ad58decceeabac3085
MD5 e7387f27a7bc16c576e6db33a6cdc317
BLAKE2b-256 9929924dfe622994522010f6e5c5e1a7d2d268caabbb77551ef2c852f5143926

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12.tar.gz:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp313-cp313-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0a3bf1ee64c6cce69426851bee50ae62fe06117a5f92fa188a8e45108c447857
MD5 7964323ef344cd6b02b831a1f9c211a0
BLAKE2b-256 5a97f2f85ac3c4a85093f829080262db8e911151d57a0ea28d0caa0d4228e8c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp313-cp313-manylinux_2_5_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp312-cp312-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 7ccc569055741b5853ca83a226f0bd93f16ce6d9c4ad3216e79c601beb7bc392
MD5 32fe3e95137c527d7180296724c8aefc
BLAKE2b-256 d603a20fac3b720e27ad682db85ec092635520bcb1a1244c12d384794e0c0e91

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp312-cp312-manylinux_2_5_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp311-cp311-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 805a1f2c0f338158be09eed73a96e16c7477c505dd3d53f8279b8d6222a12bb8
MD5 8e62d07246062d40635f333f9099246d
BLAKE2b-256 d003a9360824c436e7d988277b7755d468867b63250688c9f091f4a53029c25d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp311-cp311-manylinux_2_5_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp310-cp310-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 42ccd1bae13979eb7fc3c505544fc6dace25b897a7c4397d29901c0258c6694e
MD5 2449cbcc288fe7bdf99f8fb853ee349d
BLAKE2b-256 e68a7a4392a1927569f3c302228d3cc25956918d9c7af4de2d0269af7aa9161b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp310-cp310-manylinux_2_5_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp39-cp39-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 955bbcbfd9b8471d894e5042a5f3956eb1c7501f8d7c78f5cc5b8cf49223619f
MD5 24f005d6f08cbc2c7fc4a7f4f2aa43f3
BLAKE2b-256 ccddc87d193256549be196bc87910edb78b263826570c79e1de2ee8c07cd6a8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp39-cp39-manylinux_2_5_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp38-cp38-manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 8b9fee955a767eb2ebfca00c994a3992418c2bfdac8487b41da3edb0ba410ed2
MD5 bf105521e8ce5546b93fdc77592511f6
BLAKE2b-256 e25603ca02f7c6c85e66a8ce8aa438e2b1cb65411f8c7d034743793b03f1ca1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp38-cp38-manylinux_2_5_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 79ddd5435d96b6fa35d475907abd99ffd8ba26cb4bab4ab66233e9b023a41930
MD5 a11ed1784a97a1a42de43852be0a4a6a
BLAKE2b-256 e5b4d2acd20b888b33fcc88bf5b821ac81e701df1795a489e8b20bd746f5543b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp37-cp37m-manylinux1_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pywpsrpc-2.3.12-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 60915076490d308e92b0cede29aa8aec48eefc1a973bc8808ab5e72430b34632
MD5 91fd5e7a05e1845066778a18d0ff6832
BLAKE2b-256 16ecaa31c25480fc3b4f5ade7f1ae7ce268457fb9f10afdd58bac398fc7d8390

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywpsrpc-2.3.12-cp36-cp36m-manylinux1_x86_64.whl:

Publisher: main.yml on timxx/pywpsrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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