String 在Python中将docx转换为字符串

String 在Python中将docx转换为字符串,string,text,comparison,python-docx,String,Text,Comparison,Python Docx,我正在尝试使用以下方法读取python中的.docx文件: file1 = docx.Document('C:\\text.docx') #Reader object 从这里我如何将其转换为字符串?我实际上是在比较两个word文档。我的方法是将两者转换为字符串变量,然后进行比较。 请建议是否有任何其他方法,我可以这样做 提前谢谢 它不是回答你的实际问题,而是回答你的目标,比较word文档。支持比较word文档的功能。目前,它只支持从云存储(Aspose存储、Amazon S3、DropBox、

我正在尝试使用以下方法读取python中的.docx文件:

file1 = docx.Document('C:\\text.docx') #Reader object
从这里我如何将其转换为字符串?我实际上是在比较两个word文档。我的方法是将两者转换为字符串变量,然后进行比较。 请建议是否有任何其他方法,我可以这样做


提前谢谢

它不是回答你的实际问题,而是回答你的目标,比较word文档。支持比较word文档的功能。目前,它只支持从云存储(Aspose存储、Amazon S3、DropBox、FTP存储、Google Drive和Windows Azure存储)进行比较。但在不久的将来,我们计划比较来自streams(请求主体)的文档

我是Aspose的开发者布道者

# For complete examples and data files, please go to https://github.com/aspose-words-cloud/aspose-words-cloud-python
# Import module
import asposewordscloud
import asposewordscloud.models.requests
import os
from shutil import copyfile

# Get your credentials from https://dashboard.aspose.cloud (free registration is required).
words_api = asposewordscloud.WordsApi(app_sid='xxx-xxxx-xxxx-xxxxxxxxx',app_key='xxxxxxxxxxxxxxxxxxxxxxxxx')
words_api.api_client.configuration.host = 'https://api.aspose.cloud'

remoteFolder = 'Temp/CompareDocument'
localFolder = 'C:/Temp'
localName1 = 'compareTestDoc1.docx'
localName2 = 'compareTestDoc2.docx'
remoteName1 = 'TestCompareDocument1.docx'
remoteName2 = 'TestCompareDocument2.docx'
dest_name = 'C:/Temp/TestCompareDocumentOut.docx'

# upload files to storage
response_upload1 = words_api.upload_file(asposewordscloud.models.requests.UploadFileRequest(open(localFolder + '/' + localName1,'rb'),remoteFolder + '/' + remoteName1))
response_upload2 = words_api.upload_file(asposewordscloud.models.requests.UploadFileRequest(open(localFolder + '/' + localName2,'rb'),remoteFolder + '/' + remoteName2))

# compare documents
requestCompareData = asposewordscloud.CompareData(author='author', comparing_with_document=remoteFolder + '/' + remoteName2)
request = asposewordscloud.models.requests.CompareDocumentRequest(name=remoteName1, compare_data=requestCompareData, folder=remoteFolder, dest_file_name=remoteFolder + '/TestCompareDocumentOut.docx')
result = words_api.compare_document(request)
copyfile(result, dest_name)
print("Result {}".format(result))