How to Manipulate Microsoft Word Documents in Python using Aspose.Words REST API

Are there any programming examples how to use the Python SDK together with the Words cloud service API?

Hi Andreas,

Sorry, Python SDK examples are not available in the Words documentation at the moment. We are in the process of revamping our Cloud API documentation and SDKs and these examples will also be added once the process is done. The process will be completed soon.

Can you please share which SDK examples do you want? We will share your required examples with you as soon as possible.

I am looking for a simple example to upload a DOCX file to the server and retrieving the converted result as HTML or something else.

Hi Andreas,

You can use the following SDK example for this purpose; output format can be passed to convert method.

from common import *
from storage import Folder
from words import WordsConverter
import json
import os

try:

os.system('cls')

# sepcify App SID
SaasposeApp.app_sid = "77******-1***-4***-****-************"

# sepcify App Key
SaasposeApp.app_key = "**************"
SaasposeApp.output_location = 'd:\\temp\\'

# specify product URI
Product.base_product_uri = 'http://api.aspose.com/v1.1'

# create Folder object
folder = Folder()
folder.upload_file("Sample.doc","c:\\Sample.doc","")

# create OcrExtractor object
extractor = WordsConverter("Sample.doc")
print extractor.convert("html")
#responseStream = Folder.getFolders(folder)
#jsonData = json.loads(responseStream)
#print jsonData
print 'Done'

except Exception, ex:
print type(ex) # the exception instance
print ex.args # arguments stored in .args
print ex.errno
print ex.strerror

finally:
raw_input("Press any Key")

Once revamp is done, updated examples will be available in the documentation and you will be able to download migrated SDK from GitHub - aspose-words-cloud/aspose-words-cloud-python: A Python library for communicating with the Aspose.Words Cloud API.

Please feel free to contact us in case you have further comments or questions.

Best Regards,

Hello-

Is this response still current? Or is there an updated Python API example?

thank you,
-e

Hi,

Python examples are available in the documentation now. Please check Aspose.Words documentation http://www.aspose.com/docs/display/wordscloud/Home for Aspose.Words examples.

Please feel free to contact us in case you have further comments or questions.

Best Regards,

@yet , erik88

Kindly note Aspose.Words Cloud API Version 4.0 has introduced its cloud storage API methods. So now there is no need to use Aspose.Storage Cloud for storage operations any more.

Please find the updated sample code for uploading a file to cloud storage and download it after the required conversion. You can also check other updated unit tests of Aspose.Words Cloud SDK for Python from GitHub repo.

import asposewordscloud
import asposewordscloud.models.requests

from shutil import copyfile

api_client = asposewordscloud.ApiClient()
api_client.configuration.host = 'https://api.aspose.cloud'
api_client.configuration.api_key['api_key'] = 'xxxxxxxxxxxxxxxxxxxx' # Put your appKey here
api_client.configuration.api_key['app_sid'] = 'xxxxx-xxxx-xxxx-xxxx-xxxxxxx' # Put your appSid here

words_api = asposewordscloud.WordsApi(api_client)
filename = '02_pages.docx'
remote_name = 'TestPostDocumentSaveAs.docx'
dest_name = 'TestPostDocumentSaveAs.html'
#upload file to storage
request_upload = asposewordscloud.models.requests.UploadFileRequest(filename,remote_name)
response_upload = words_api.upload_file(request_upload)
#Convert DOCX to HTML and save to storage
save_options = asposewordscloud.SaveOptionsData(save_format='html', file_name=dest_name)
request_conversion = asposewordscloud.models.requests.SaveAsRequest(remote_name, save_options)
response_conversion = words_api.save_as(request_conversion)
#download file from storage
request_download=asposewordscloud.models.requests.DownloadFileRequest(dest_name)
response_download = words_api.download_file(request_download)
copyfile(response_download, 'C:/Temp/02_pagesSaveAs.html')
print("Result {}".format(response_download))