在Openpyxl Python中将列格式设置为百分比

编程入门 行业动态 更新时间:2024-10-26 00:23:12
本文介绍了在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?

我已经浏览过此页面:

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中将列格式设置为百分比

本文发布于:2023-10-30 08:05:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542262.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:百分比   设置为   中将   格式   Openpyxl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!