Learn how to Merge and Unmerge Cells in Excel using Python
Created
January 29, 2025 12:33
Merge and Unmerge Cells in Excel using Python
This file contains 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
import aspose.cells as cells | |
# Create a new workbook | |
workbook = cells.Workbook() | |
# Access the first worksheet | |
worksheet = workbook.worksheets.get(0) | |
# Create a Range | |
range = worksheet.cells.create_range("A1:D4") | |
# Merge range into a single cell | |
range.merge() | |
# Save the workbook | |
workbook.save("MergeRangeOfCells.xlsx") |
This file contains 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
import aspose.cells as cells | |
# Create a new workbook | |
workbook = cells.Workbook() | |
# Access the first worksheet | |
worksheet = workbook.worksheets.get(0) | |
worksheet_cells = worksheet.cells | |
# Merge cells A1 to C1 | |
worksheet_cells.merge(0, 0, 1, 3); | |
# Save the workbook | |
workbook.save("MergedCells.xlsx") |
This file contains 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
import aspose.cells as cells | |
# Load a workbook | |
workbook = cells.Workbook("MergedCells.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets.get(0) | |
worksheet_cells = worksheet.cells | |
# Unmerge cells A1 to C1 | |
worksheet_cells.un_merge(0, 0, 1, 3); | |
# Save the workbook | |
workbook.save("UnmergedCells.xlsx") |
This file contains 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
import aspose.cells as cells | |
# Create a new workbook | |
workbook = cells.Workbook("MergeRangeOfCells.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets.get(0) | |
# Create a Range | |
range = worksheet.cells.create_range("A1:D4") | |
# Merge range into a single cell | |
range.un_merge() | |
# Save the workbook | |
workbook.save("UnmergeRangeOfCells.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment