使用openpyxl更改所有单元格的样式 [英] Alter the style of all cells with openpyxl

查看:1933
本文介绍了使用openpyxl更改所有单元格的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将openpyxl 2.0.3与python2.7配合使用.

I'm using openpyxl 2.0.3 with python2.7.

是否可以将样式应用于工作表中的每个单元格?可以说我要更改所有单元格的字体,类似于我打开excel文档,按ctrl + a,右键单击并更改格式的方式.

Is there a way to apply a style to every cell in a worksheet? Lets say I want to change the font of all cells, similar to how I would open an excel document, hit ctrl+a, right click and change the format.

推荐答案

没有方法可以做到这一点.目前最好的方法可能是为所有相关的列或行设置样式

There is no method to do this. At the moment the best approach would probably be to set the style for all the relevant columns or rows

style = Style(…)
for col in 'ABCD':
     ws._styles['A'] = style

我认为我们将在即将发布的版本中改进处理方式.

I think we'll be working on improving handling styles in coming releases.

这篇关于使用openpyxl更改所有单元格的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆