Created
June 22, 2025 17:37
-
-
Save aspose-cloud-kb/0f9607eb74246198a86bef1c2fa12e05 to your computer and use it in GitHub Desktop.
Combine Excel Files using Python REST API. https://kb.aspose.cloud/cells/python/combine-excel-files-using-python-rest-api/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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