在Openpyxl Python中将列格式设置为百分比 [英] Format column as percentage in Openpyxl Python

查看:3900
本文介绍了在Openpyxl Python中将列格式设置为百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想使用Openpyxl for Python将某些列划分为百分比.我不知道如何将单元格的格式更改为另一种类型?

I just want to make certain columns into percentages using Openpyxl for Python. I can't figure out how to change the formatting of the cells to another type?

我已经浏览过此页面:

http://openpyxl.readthedocs.io/en/default/styles.html

但是,如果我尝试这样做:

But if I try doing:

ws['A:A'].style = percent

我收到ValueError:样式百分比已存在.我确定我犯了一些愚蠢的错误,但我不知道这是什么.我见过其他有关人们希望将格式更改为货币的主题,这些主题使用不同的数字格式,但与百分比无关.

I get ValueError: Style percent exists already. I'm sure I'm making some stupid mistake, but I can't figure out what it is. I've seen other threads about people wanting to change formats to currencies, which uses a different number formatting, but nothing about percentages.

推荐答案

您只能设置单个单元格的格式,不能设置单元格范围或列或行的格式.

You can only format individual cells not cell ranges or columns or rows.

这篇关于在Openpyxl Python中将列格式设置为百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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