Last active
January 27, 2024 04:24
-
-
Save aspose-com-kb/586fa28dfbf5f78e7d078ca1f2be6371 to your computer and use it in GitHub Desktop.
Add Borders in Excel using Python. For more details: https://kb.aspose.com/cells/python/add-borders-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 jpype | |
jpype.startJVM() | |
from asposecells.api import Workbook, CellBorderType, Color | |
# Instantiate a workbook | |
book = Workbook() | |
# Get access to a sheet | |
sheet = book.getWorksheets().get("Sheet1") | |
# Set sample text | |
sheet.getCells().get(1, 0).putValue("Thick Lines") | |
# Create a range of cells for setting border | |
borderRange = sheet.getCells().createRange("C2", "C2") | |
# Set the borders for the defined range of cells | |
borderRange.setOutlineBorders(CellBorderType.THICK, Color.getBlack()) | |
# Adjust columns width | |
sheet.autoFitColumn(2) | |
# Save the output | |
book.save("Borders.xlsx") | |
print("Border added successfully") | |
jpype.shutdownJVM() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment