Merge Excel spreadsheets

GroupDocs.Merger for Python via .NET allows you to combine multiple Excel spreadsheets into a single file programmatically. All worksheets, data, formulas, charts, and formatting are preserved — no Microsoft Excel or third-party software required.

Spreadsheet files store data in rows and columns and are saved in formats such as XLSX (Microsoft Excel Open XML Spreadsheet), XLS (Microsoft Excel Binary File Format), and ODS (OpenDocument Spreadsheet). XLSX is the default format introduced with Microsoft Office 2007, based on the Open Packaging Conventions (OOXML/ECMA-376 standard).

Steps to merge XLSX files

  1. Create an instance of the Merger class and pass the path to the first (base) XLSX file.
  2. Call merger.join() with the path to each additional XLSX file to append.
  3. Call merger.save() with the desired output path to write the merged file.
from groupdocs.merger import Merger

def merge_excel_documents():
    # Load the first document as the merge base
    with Merger("./input.xlsx") as merger:
        # Append the second Excel spreadsheet
        merger.join("./input2.xlsx")
        # Save the combined document
        merger.save("./output.xlsx")

if __name__ == "__main__":
    merge_excel_documents()

input.xlsx is a sample file used in this example. Click here to download it.

input2.xlsx is a sample file used in this example. Click here to download it.

Binary file (XLSX, 18 KB)

Download full output

Explanation

  • Load base document: Merger("./input.xlsx") opens the first Excel spreadsheet as the merge base inside a context manager.
  • Append second document: merger.join("./input2.xlsx") appends all worksheets from the second file. Call join again for each additional file.
  • Save result: merger.save("./output.xlsx") writes the merged spreadsheet to disk.

Merge XLSX Live Demo

GroupDocs.Merger for Python via .NET provides an online XLSX Merger App, which allows you to try it for free and check its quality and accuracy.

API reference

  • Merger — main class; join, save methods.

See also