openpyxl python 框线_python – 在OpenPyxl中将边框应用于单元格

我正在尝试使用Openpyxl将边框应用于单元格,但我在最基本的“将任何类型的边框应用于任何位置的任何单元格”任务上都失败了.我尝试从Openpyxl文档(http://pythonhosted.org/openpyxl/styles.html#introduction)默认样式进行复制并修改,但这给了我

“TypeError:init() got an unexpected keyword argument ‘superscript'”

AttributeError: type object ‘Border’ has no attribute ‘BORDER_THIN’

(即使我修正了拼写错误和导入错误不足).

有谁知道如何使用Python 3.3和OpenPyxl 2.0.4应用边框?我正在寻找的是一段代码,如果我将其复制粘贴到空白脚本中,将在工作簿中的任何单元格周围放置边框.

解决方法:

使用openpyxl 2.2.5版本,此代码段适用于我:

from openpyxl.styles.borders import Border, Side

from openpyxl import Workbook

thin_border = Border(left=Side(style='thin'),

right=Side(style='thin'),

top=Side(style='thin'),

bottom=Side(style='thin'))

wb = Workbook()

ws = wb.get_active_sheet()

# property cell.border should be used instead of cell.style.border

ws.cell(row=3, column=2).border = thin_border

wb.save('border_test.xlsx')

标签:openpyxl,python

来源: https://codeday.me/bug/20191005/1855731.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值