Skip to content

Instantly share code, notes, and snippets.

@groupdocscloud
Last active February 12, 2021 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocscloud/49c298f42348259cd85175f315d57272 to your computer and use it in GitHub Desktop.
Save groupdocscloud/49c298f42348259cd85175f315d57272 to your computer and use it in GitHub Desktop.
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
configuration = groupdocs_editor_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Copy_File:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FileApi_Instance()
try:
request = groupdocs_Editor_cloud.CopyFileRequest("Editordocs\\one-page.docx", "Editordocs\\one-page-copied.docx", Common_Utilities.myStorage, Common_Utilities.myStorage)
api.copy_file(request)
print("Expected response type is Void: 'Editordocs/one-page.docx' file copied as 'Editordocs/one-page-copied.docx'.")
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Copy_Folder:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FolderApi_Instance()
try:
request = groupdocs_Editor_cloud.CopyFolderRequest("Editordocs", "Editordocs1", Common_Utilities.myStorage, Common_Utilities.myStorage)
api.copy_folder(request)
print("Expected response type is Void: 'Editordocs' folder copied as 'Editordocs1'.")
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Create_Folder:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FolderApi_Instance()
try:
request = groupdocs_Editor_cloud.CreateFolderRequest("Assembler", Common_Utilities.myStorage)
api.create_folder(request)
print("Expected response type is Void: 'Assembler' folder created.")
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Delete_File:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FileApi_Instance()
try:
request = groupdocs_Editor_cloud.DeleteFileRequest("Editordocs1\\one-page.docx", Common_Utilities.myStorage)
api.delete_file(request)
print("Expected response type is Void: 'Editordocs1/one-page.docx' deleted.")
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Delete_Folder:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FolderApi_Instance()
try:
request = groupdocs_Editor_cloud.DeleteFolderRequest("Editordocs\\Editordocs1", Common_Utilities.myStorage, True)
api.delete_folder(request)
print("Expected response type is Void: 'Editordocs/Editordocs1' folder deleted recursively.")
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
request = groupdocs_editor_cloud.DownloadFileRequest("output\\edited.docx", my_storage)
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\")
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Download_File:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FileApi_Instance()
try:
request = groupdocs_Editor_cloud.DownloadFileRequest("Editordocs\\one-page.docx", Common_Utilities.myStorage)
response = api.download_file(request)
print("Expected response type is Stream: " + str(len(response)))
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Create necessary API instances
edit_api = groupdocs_editor_cloud.EditApi.from_config(configurations)
file_api = groupdocs_editor_cloud.FileApi.from_config(configurations)
# The document already uploaded into the storage.
# Load it into editable state
file_info = groupdocs_editor_cloud.FileInfo("sample_four_sheets.xlsx")
load_options = groupdocs_editor_cloud.SpreadsheetLoadOptions()
load_options.file_info = file_info
load_options.output_path = "output"
load_options.worksheet_index = 0
load_result = edit_api.load(groupdocs_editor_cloud.LoadRequest(load_options))
# Download html document
html_file = file_api.download_file(groupdocs_editor_cloud.DownloadFileRequest(load_result.html_path))
html = ""
with open(html_file, 'r') as file:
html = file.read()
# Edit something...
html = html.replace("This is sample sheet", "This is sample sheep")
# Upload html back to storage
with open(html_file, 'w') as file:
file.write(html)
file_api.upload_file(groupdocs_editor_cloud.UploadFileRequest(load_result.html_path, html_file))
# Save html back to xlsx
save_options = groupdocs_editor_cloud.SpreadsheetSaveOptions()
save_options.file_info = file_info
save_options.output_path = "output/edited.xlsx"
save_options.html_path = load_result.html_path
save_options.resources_path = load_result.resources_path
save_result = edit_api.save(groupdocs_editor_cloud.SaveRequest(save_options))
# Done
print("Excel sheet edited: " + save_result.path)
# Create necessary API instances
edit_api = groupdocs_editor_cloud.EditApi.from_config(configurations)
file_api = groupdocs_editor_cloud.FileApi.from_config(configuration)
# The document already uploaded into the storage.
# Load it into editable state
file_info = groupdocs_editor_cloud.FileInfo("sample_word_document.docx", None, None, None)
load_options = groupdocs_editor_cloud.WordProcessingLoadOptions()
load_options.file_info = file_info
load_options.output_path = "output"
load_result = edit_api.load(groupdocs_editor_cloud.LoadRequest(load_options))
# Download html document
html_file = file_api.download_file(groupdocs_editor_cloud.DownloadFileRequest(load_result.html_path))
html = ""
with open(html_file, 'r') as file:
html = file.read()
# Edit something...
html = html.replace("Sample test text", "Hello world")
# Upload html back to storage
with open(html_file, 'w') as file:
file.write(html)
file_api.upload_file(groupdocs_editor_cloud.UploadFileRequest(load_result.html_path, html_file))
# Save html back to docx
save_options = groupdocs_editor_cloud.WordProcessingSaveOptions()
save_options.file_info = file_info
save_options.output_path = "output/edited.docx"
save_options.html_path = load_result.html_path
save_options.resources_path = load_result.resources_path
save_result = edit_api.save(groupdocs_editor_cloud.SaveRequest(save_options))
# Done
print("Document edited: " + save_result.path)
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Get_Disc_Usage:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_StorageApi_Instance()
try:
request = groupdocs_Editor_cloud.GetDiscUsageRequest(Common_Utilities.myStorage)
response = api.get_disc_usage(request)
print("Expected response type is DiscUsage: " + str(response))
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-python-samples
import groupdocs_editor_cloud
app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
infoApi = groupdocs_editor_cloud.InfoApi.from_keys(app_sid, app_key)
result = infoApi.get_supported_file_formats()
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-python-samples
import groupdocs_editor_cloud
app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
infoApi = groupdocs_editor_cloud.InfoApi.from_keys(app_sid, app_key)
fileInfo = groupdocs_editor_cloud.FileInfo("WordProcessing/password-protected.docx", None, None, "password")
result = infoApi.get_info(groupdocs_editor_cloud.GetInfoRequest(fileInfo))
print("Page count = " + str(result.page_count))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Get_File_Versions:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_StorageApi_Instance()
try:
request = groupdocs_Editor_cloud.GetFileVersionsRequest("Editordocs\\one-page.docx", Common_Utilities.myStorage)
response = api.get_file_versions(request)
print("Expected response type is FileVersions: " + str(response))
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Get_Files_List:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FolderApi_Instance()
try:
request = groupdocs_Editor_cloud.GetFilesListRequest("Editordocs\\sample.docx", Common_Utilities.myStorage)
response = api.get_files_list(request)
print("Expected response type is FilesList: " + str(response))
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Move_File:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FileApi_Instance()
try:
request = groupdocs_Editor_cloud.MoveFileRequest("Editordocs\\one-page.docx", "Editordocs1\\one-page.docx", Common_Utilities.myStorage, Common_Utilities.myStorage)
api.move_file(request)
print("Expected response type is Void: 'Editordocs/one-page.docx' file moved to 'Editordocs1/one-page.docx'.")
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Move_Folder:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FolderApi_Instance()
try:
request = groupdocs_Editor_cloud.MoveFolderRequest("Editordocs1", "Editordocs1\\Editordocs", Common_Utilities.myStorage, Common_Utilities.myStorage)
api.move_folder(request)
print("Expected response type is Void: 'Editordocs1' folder moved to 'Editordocs/Editordocs1'.")
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Object_Exists:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_StorageApi_Instance()
try:
request = groupdocs_Editor_cloud.ObjectExistsRequest("Editordocs\\one-page.docx", Common_Utilities.myStorage)
response = api.object_exists(request)
print("Expected response type is ObjectExist: " + str(response))
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Storage_Exist:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_StorageApi_Instance()
try:
request = groupdocs_Editor_cloud.StorageExistsRequest(Common_Utilities.myStorage)
response = api.storage_exists(request)
print("Expected response type is StorageExist: " + str(response))
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import modules
import groupdocs_Editor_cloud
from Common_Utilities.Utils import Common_Utilities
class Editor_Python_Upload_File:
@classmethod
def Run(self):
# Create instance of the API
api = Common_Utilities.Get_FileApi_Instance()
try:
request = groupdocs_Editor_cloud.UploadFileRequest("Editordocs\\one-page.docx", "D:\\ewspace\\GroupDocs.Editor.Cloud.Python.Examples\\src\\Resources\\Editordocs\\one-page.docx", Common_Utilities.myStorage)
response = api.upload_file(request)
print("Expected response type is FilesUploadResult: " + str(response))
except groupdocs_Editor_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
storage_api = groupdocs_editor_cloud.StorageApi.from_config(config_info)
file_api = groupdocs_editor_cloud.FileApi.from_config(config_info)
# upload sample file
files = glob.glob("C:\\Files\\sample_word_document.docx", recursive=False)
destination_file = files[0].replace("C:\\Files\\", "", 1)
file_api.upload_file(groupdocs_editor_cloud.UploadFileRequest(destination_file, files[0]))
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-python-samples
import groupdocs_editor_cloud
app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
editApi = groupdocs_editor_cloud.EditApi.from_keys(app_sid, app_key)
fileApi = groupdocs_editor_cloud.FileApi.from_keys(app_sid, app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = groupdocs_editor_cloud.FileInfo("Spreadsheet/sample.tsv")
loadOptions = groupdocs_editor_cloud.DelimitedTextLoadOptions()
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadResult = editApi.load(groupdocs_editor_cloud.LoadRequest(loadOptions))
# Download html document
htmlFile = fileApi.download_file(groupdocs_editor_cloud.DownloadFileRequest(loadResult.html_path))
html = ""
with open(htmlFile, 'r') as file:
html = file.read()
# Edit something...
html = html.replace("32", "66")
# Upload html back to storage
with open(htmlFile, 'w') as file:
file.write(html)
fileApi.upload_file(groupdocs_editor_cloud.UploadFileRequest(loadResult.html_path, htmlFile))
# Save html back to tsv
saveOptions = groupdocs_editor_cloud.DelimitedTextSaveOptions()
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.tsv"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveResult = editApi.save(groupdocs_editor_cloud.SaveRequest(saveOptions))
# Done
print("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-python-samples
import groupdocs_editor_cloud
app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
editApi = groupdocs_editor_cloud.EditApi.from_keys(app_sid, app_key)
fileApi = groupdocs_editor_cloud.FileApi.from_keys(app_sid, app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = groupdocs_editor_cloud.FileInfo("Presentation/with-notes.pptx")
loadOptions = groupdocs_editor_cloud.PresentationLoadOptions()
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadOptions.slide_number = 0
loadResult = editApi.load(groupdocs_editor_cloud.LoadRequest(loadOptions))
# Download html document
htmlFile = fileApi.download_file(groupdocs_editor_cloud.DownloadFileRequest(loadResult.html_path))
html = ""
with open(htmlFile, 'r') as file:
html = file.read()
# Edit something...
html = html.replace("Slide sub-heading", "Hello world!")
# Upload html back to storage
with open(htmlFile, 'w') as file:
file.write(html)
fileApi.upload_file(groupdocs_editor_cloud.UploadFileRequest(loadResult.html_path, htmlFile))
# Save html back to pptx
saveOptions = groupdocs_editor_cloud.PresentationSaveOptions()
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.pptx"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveResult = editApi.save(groupdocs_editor_cloud.SaveRequest(saveOptions))
# Done
print("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-python-samples
import groupdocs_editor_cloud
app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
editApi = groupdocs_editor_cloud.EditApi.from_keys(app_sid, app_key)
fileApi = groupdocs_editor_cloud.FileApi.from_keys(app_sid, app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = groupdocs_editor_cloud.FileInfo("Spreadsheet/four-sheets.xlsx")
loadOptions = groupdocs_editor_cloud.SpreadsheetLoadOptions()
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadOptions.worksheet_index = 0
loadResult = editApi.load(groupdocs_editor_cloud.LoadRequest(loadOptions))
# Download html document
htmlFile = fileApi.download_file(groupdocs_editor_cloud.DownloadFileRequest(loadResult.html_path))
html = ""
with open(htmlFile, 'r') as file:
html = file.read()
# Edit something...
html = html.replace("This is sample sheet", "This is sample sheep")
# Upload html back to storage
with open(htmlFile, 'w') as file:
file.write(html)
fileApi.upload_file(groupdocs_editor_cloud.UploadFileRequest(loadResult.html_path, htmlFile))
# Save html back to xlsx
saveOptions = groupdocs_editor_cloud.SpreadsheetSaveOptions()
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.xlsx"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveResult = editApi.save(groupdocs_editor_cloud.SaveRequest(saveOptions))
# Done
print("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-python-samples
import groupdocs_editor_cloud
app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
editApi = groupdocs_editor_cloud.EditApi.from_keys(app_sid, app_key)
fileApi = groupdocs_editor_cloud.FileApi.from_keys(app_sid, app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = groupdocs_editor_cloud.FileInfo("Text/document.txt")
loadOptions = groupdocs_editor_cloud.TextLoadOptions()
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadResult = editApi.load(groupdocs_editor_cloud.LoadRequest(loadOptions))
# Download html document
htmlFile = fileApi.download_file(groupdocs_editor_cloud.DownloadFileRequest(loadResult.html_path))
html = ""
with open(htmlFile, 'r') as file:
html = file.read()
# Edit something...
html = html.replace("Page Text", "New Text")
# Upload html back to storage
with open(htmlFile, 'w') as file:
file.write(html)
fileApi.upload_file(groupdocs_editor_cloud.UploadFileRequest(loadResult.html_path, htmlFile))
# Save html back to txt
saveOptions = groupdocs_editor_cloud.TextSaveOptions()
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.txt"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveResult = editApi.save(groupdocs_editor_cloud.SaveRequest(saveOptions))
# Done
print("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-python-samples
import groupdocs_editor_cloud
app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
editApi = groupdocs_editor_cloud.EditApi.from_keys(app_sid, app_key)
fileApi = groupdocs_editor_cloud.FileApi.from_keys(app_sid, app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = groupdocs_editor_cloud.FileInfo("WordProcessing/password-protected.docx", None, None, "password")
loadOptions = groupdocs_editor_cloud.WordProcessingLoadOptions()
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadResult = editApi.load(groupdocs_editor_cloud.LoadRequest(loadOptions))
# Download html document
htmlFile = fileApi.download_file(groupdocs_editor_cloud.DownloadFileRequest(loadResult.html_path))
html = ""
with open(htmlFile, 'r') as file:
html = file.read()
# Edit something...
html = html.replace("Sample test text", "Hello world")
# Upload html back to storage
with open(htmlFile, 'w') as file:
file.write(html)
fileApi.upload_file(groupdocs_editor_cloud.UploadFileRequest(loadResult.html_path, htmlFile))
# Save html back to docx
saveOptions = groupdocs_editor_cloud.WordProcessingSaveOptions()
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.docx"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveResult = editApi.save(groupdocs_editor_cloud.SaveRequest(saveOptions))
# Done
print("Document edited: " + saveResult.path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment