Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active January 27, 2024 04:24
Show Gist options
  • Save aspose-com-kb/586fa28dfbf5f78e7d078ca1f2be6371 to your computer and use it in GitHub Desktop.
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/
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