如果您想打开一个文本文件并以纯文本格式处理数据,您可以使用 Python 语言和操作系统的最基本功能来完成。至于阅读以多种文件格式(DOCX、DOC、PDF、RTF、ODT、HTML 等)呈现的办公文档,这个任务更难解决,因为这些文档是由复杂的树状数据描述的DOM 模型中的结构。
我们的 Python 库是一个基于云的解决方案,可让您以任何办公室和 Web 格式打开文档。这种分布式方法使您可以灵活地使用 Python 语言进行软件开发,因为所有资源密集型文档处理都将在 Aspose 服务器上进行。您只需要获取私钥即可在 Python 代码中访问 Cloud API。
您可以迭代文档元素,也可以在 DOM 树中搜索特定元素。我们提供了广泛的 Python 函数,用于处理文档结构和文档节点中包含的数据。
以下 Python 代码示例将帮助您快速了解如何加载文档并对其执行一些操作。
import asposewordscloud
words_api = WordsApi(client_id = '####-####-####-####-####', client_secret = '##################')
file_name= 'Input.docx'
request_file_content = open(open(file_name).read(), 'rb')
upload_document_request = asposewordscloud.models.requests.UploadFileRequest(
file_content=request_file_content, path=file_name)
words_api.upload_file(upload_document_request)
request_paragraph = asposewordscloud.ParagraphInsert(
text='Reading and writing to the file in the cloud occurs automatically.')
insert_paragraph_request = asposewordscloud.models.requests.InsertParagraphRequest(
name=file_name, paragraph=request_paragraph)
words_api.insert_paragraph(insert_paragraph_request)
download_document_request = asposewordscloud.models.requests.DownloadFileRequest(
path=file_name)
words_api.download_file(download_document_request)
使用 PyPi 存储库安装 Aspose.Words Cloud SDK for Python 。运行 pip install aspose-words-cloud 安装 SDK,然后通过 import asposewordscloud 导入包。作为替代方案,您可以从 GitHub 手动克隆 Aspose.Words Cloud SDK for Python 源代码并在您的项目中使用它。请按照这些 Instructions 快速获取必要的安全凭证并访问我们的 REST API。
请参阅 Repository Documentation 以查看详细信息。