Last active
May 4, 2022 13:30
-
-
Save aspose-com-gists/db8bf666a8cfa3faf857e1ad608149f3 to your computer and use it in GitHub Desktop.
Insert and Delete Rows and Columns in Excel using Python | https://blog.aspose.com/2021/04/13/insert-and-delete-rows-and-columns-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
# Instantiate a Workbook object by excel file path | |
workbook = self.Workbook('Book1.xls') | |
# Access the first worksheet in the Excel file | |
worksheet = workbook.getWorksheets().get(0) | |
# Delete a column from the worksheet at 2nd position | |
worksheet.getCells().deleteColumns(1,1,True) | |
# Save the modified Excel file in default (that is Excel 2003) format | |
workbook.save("Insert Column.xls") |
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
# Instantiate a Workbook object by excel file path | |
workbook = self.Workbook("Book1.xls") | |
# Access the first worksheet in the Excel file | |
worksheet = workbook.getWorksheets().get(0) | |
# Delete 10 rows from the worksheet starting from 3rd row | |
worksheet.getCells().deleteRows(2,10,True) | |
# Save the modified Excel file in default (that is Excel 2003) format | |
workbook.save("Insert Row.xls") |
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
# Instantiate a Workbook object by excel file path | |
workbook = self.Workbook('Book1.xls') | |
# Access the first worksheet in the Excel file | |
worksheet = workbook.getWorksheets().get(0) | |
# Insert a column into the worksheet at 2nd position | |
worksheet.getCells().insertColumns(1,1) | |
# Save the modified Excel file in default (that is Excel 2003) format | |
workbook.save("Insert Column.xls") |
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
# Instantiate a Workbook object by excel file path | |
workbook = self.Workbook("Book1.xls") | |
# Access the first worksheet in the Excel file | |
worksheet = workbook.getWorksheets().get(0) | |
# Insert a row into the worksheet at 3rd position | |
worksheet.getCells().insertRows(2,1) | |
# Save the modified Excel file in default (that is Excel 2003) format | |
workbook.save("Insert Row.xls") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the article: https://blog.aspose.com/2021/04/13/insert-and-delete-rows-and-columns-in-excel-using-python/