Skip to main content

基于 Python 开发的自动化 office 工具包

Project description

安装

office-tool-plus 一些自动化办公的工具包

# 国内源
pip install --upgrade office-tool-plus -i https://mirrors.aliyun.com/pypi/simple/ 
# 官方源(最新版)
pip install --upgrade office-tool-plus -i https://pypi.org/simple  

使用

excel

single_to_pdf(excel_path: str, sheet_names: list = None, pdf_dir: str = None):

将指定Excel工作簿中的工作表导出为PDF格式。

参数:

  • excel_path: Excel文件的路径。
  • sheet_names: 需要导出的工作表名称列表。如果未提供,则默认导出所有工作表。
  • pdf_dir: PDF文件的保存目录。如果未提供,则默认保存在Excel文件的同目录下。

返回:

  • pdf_path: 导出的PDF文件路径。

示例:

from office_tool_plus import ExcelTools

excel = ExcelTools()
# 将整个 Excel 导出为 pdf,并保存在源目录下
excel.single_to_pdf('test.xlsx')
# 将整个 Excel 导出为 pdf,并保存在 output 目录下
excel.single_to_pdf('test.xlsx', pdf_dir='output')
# 将指定 sheet 导出为 pdf,并保存在源目录下
excel.single_to_pdf('test.xlsx', ['Sheet1', 'Sheet2'])
# 将指定 sheet 导出为 pdf,并保存在 output 目录下
excel.single_to_pdf('test.xlsx', ['Sheet1', 'Sheet2'], 'output')

many_to_pdf(excel_dir: str, suffix: list = None, recursive=True, pdf_dir: str = None):

将指定目录下的Excel文件批量导出为PDF格式。

参数:

  • excel_dir: Excel文件的目录路径。
  • suffix: 需要导出的文件后缀名列表。如果未提供,则默认导出["*.xlsx", "*.xls"]
  • recursive: 是否递归搜索子目录。如果为True,则递归搜索子目录,否则只搜索当前目录。
  • pdf_dir: PDF文件的保存目录。如果未提供,则默认保存在Excel文件的同目录下。

返回:

  • None

示例:

from office_tool_plus import ExcelTools

excel = ExcelTools()
# 将 test 目录下(包含子目录)所有的 Excel 文件批量导出为 pdf,并保存在源目录下
excel.many_to_pdf('test')
# 将 test 目录下(包含子目录)所有的 Excel 文件批量导出为 pdf,并保存在 output 目录下
excel.many_to_pdf('test', pdf_dir='output')
# 将 test 目录下(不包含子目录)所有的 Excel 文件批量导出为 pdf,并保存在源目录下
excel.many_to_pdf('test', recursive=False)
# 将 test 目录下(不包含子目录),后缀是 *.xlsx 的 Excel 文件批量导出为 pdf,并保存在 output 目录下
excel.many_to_pdf('test', suffix=['*.xlsx'], recursive=False, pdf_dir='output')

word

single_to_pdf(word_path: str, pdf_dir: str = None):

将指定的Word文档导出为PDF格式。

参数:

  • word_path: Word文件的路径。
  • pdf_dir: PDF文件的保存目录。如果未提供,则默认保存在Word文件的同目录下。

返回:

  • pdf_path: 导出的PDF文件路径。

示例:

from office_tool_plus import WordTools

word = WordTools()
# 将指定的 Word 导出为 pdf,并保存在源目录下
word.single_to_pdf('test.docx')
# 将指定的 Word 导出为 pdf,并保存在 output 目录下
word.single_to_pdf('test.docx', pdf_dir='output')

many_to_pdf(word_dir: str, suffix: list = None, recursive=True, pdf_dir: str = None):

将指定目录下的Word文件批量导出为PDF格式。

参数:

  • word_dir: Word文件的目录路径。
  • suffix: 需要导出的文件后缀名列表。如果未提供,则默认导出["*.docx", "*.doc"]
  • recursive: 是否递归搜索子目录。如果为True,则递归搜索子目录,否则只搜索当前目录。
  • pdf_dir: PDF文件的保存目录。如果未提供,则默认保存在Word文件的同目录下。

返回:

  • None

示例:

from office_tool_plus import WordTools

word = WordTools()
# 将 test 目录下(包含子目录)所有的 Word 文件批量导出为 pdf ,并保存在源目录下
word.many_to_pdf('test')
# 将 test 目录下(包含子目录)所有的 Word 文件批量导出为 pdf,并保存在 output 目录下
word.many_to_pdf('test', pdf_dir='output')
# 将 test 目录下(不包含子目录)所有的 Word 文件批量导出为 pdf,并保存在源目录下
word.many_to_pdf('test', recursive=False)
# 将 test 目录下(不包含子目录),后缀是 *.docx 的 Word 文件批量导出为 pdf,并保存在 output 目录下
word.many_to_pdf('test', suffix=['*.docx'], recursive=False, pdf_dir='output')

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

office_tool_plus-0.0.7.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

office_tool_plus-0.0.7-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file office_tool_plus-0.0.7.tar.gz.

File metadata

  • Download URL: office_tool_plus-0.0.7.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for office_tool_plus-0.0.7.tar.gz
Algorithm Hash digest
SHA256 0c61cfd09a134dd5e4e79ce261110fa0c24f551907cae17dbcd2dce42079e130
MD5 270634ed6f48381d271b9fcb413c5564
BLAKE2b-256 168ffdc23d2f43b34ed0e2f2307427ef61bb70b3c7e7121446dacd937e223649

See more details on using hashes here.

File details

Details for the file office_tool_plus-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for office_tool_plus-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0dd901702808a445675bd71e345e557b08a064f335b17381a9d8c3bf87103488
MD5 966d905c1d5c9bfa9fd4ed7c484cc702
BLAKE2b-256 4f2977d5e46c700e63a1ec3e608735e5656a03b4c1adf3aabfcd46e336f6e085

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