最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】openpyxl中设置单元格自动换行

Python crifan 15597浏览 0评论

之前已经折腾过:

【部分解决】openpyxl的excel设置列宽自适应+设置行高

但是没法自适应列宽,导致现在设置了cell的value后,显示效果很不好:

想要实现,类似于手动设置的:

的效果:

即:设置单元格的自动换行

openpyxl cell auto new line

openpyxl cell wrap text

python – Writing multi-line strings into cells using openpyxl – Stack Overflow

【总结】

最后是用:

<code># curCell.style.alignment.wrap_text = True #AttributeError: 'str' object has no attribute 'alignment'
curCell.alignment = Alignment(wrapText=True)
</code>

实现了自动换行的效果:

转载请注明:在路上 » 【已解决】openpyxl中设置单元格自动换行

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.176 seconds, using 22.11MB memory