Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-cloud-kb/0f9607eb74246198a86bef1c2fa12e05 to your computer and use it in GitHub Desktop.
Save aspose-cloud-kb/0f9607eb74246198a86bef1c2fa12e05 to your computer and use it in GitHub Desktop.
from asposecellscloud import CellsApi, PostWorkbooksMergeRequest
from asposecellscloud.rest import ApiException
import os
def main():
try:
# Set your client id and secret here or via environment variables
client_id = os.getenv("ASPOSE_CELLS_CLOUD_CLIENT_ID")
client_secret = os.getenv("ASPOSE_CELLS_CLOUD_CLIENT_SECRET")
cells_api = CellsApi(client_id, client_secret)
primary_workbook = "charts.xlsx"
secondary_workbook = "budget.xlsx"
# Upload files to Aspose Cloud storage
with open(primary_workbook, 'rb') as file1:
cells_api.upload_file(primary_workbook, file1)
with open(secondary_workbook, 'rb') as file2:
cells_api.upload_file(secondary_workbook, file2)
# Prepare and execute merge request
merge_request = PostWorkbooksMergeRequest(name=primary_workbook, merge_with=secondary_workbook)
cells_api.post_workbooks_merge(merge_request)
# Download the merged workbook
merged_stream = cells_api.download_file(primary_workbook)
# Save merged workbook locally
with open("output.xlsx", "wb") as output_file:
output_file.write(merged_stream.read())
print("Merging of Excel workbooks completed successfully.")
except ApiException as e:
print(f"API Exception: {e}")
except Exception as e:
print(f"Exception occurred: {e}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment