openpyxl设置单元格边框,需要使用Border 和 Side
import openpyxl
from openpyxl.styles import Border, Side
wb = openpyxl.Workbook() # 创建一个excel文件
sheet = wb.active # 获得一个的工作表
sheet.title = "边框控制"
border = Border(left=Side(border_style='thin', color='000000'),
right=Side(border_style='mediumDashed', color='000000'),
top=Side(border_style='double', color='000000'),
bottom=Side(border_style='dashed', color='000000'))
sheet['B2'].border = border
wb.save("./data/边框.xlsx")
border_style 可以控制边框的样式,下面是可用的样式
style = NoneSet(values=('dashDot','dashDotDot', 'dashed','dotted',
'double','hair', 'medium', 'mediumDashDot', 'mediumDashDotDot',
'mediumDashed', 'slantDashDot', 'thick', 'thin')
)
最终的效果图如下
QQ交流群: 211426309