[英]I want to display my EXCEL data with “%” sign. How can i do so by using python
i am creating an Excel data sheet where i need to show my data both in number and with a percentage sign. 我正在创建一个Excel数据表,在这里我需要同时显示数字和百分号。 but when i use percentage from Excel data type it adds some extra zero (9600%).
但是,当我使用Excel数据类型的百分比时,它会添加一些额外的零(9600%)。 but i don't want it like this.
但我不想这样。 my requirement for data is only with the percentage sign (96%).
我对数据的要求仅带有百分号(96%)。 Can i do this by using Excel of Python.
我可以使用Python的Excel做到这一点吗?
Using a 0.42
as value for your cell will lead to 42%
- setting 42
into that cell, you will get 4200%
. 使用
0.42
作为单元格的值将导致42%
-将42
设置为该单元格,您将获得4200%
。
from openpyxl import Workbook # openpyxel 2.5.9
wb = Workbook()
ws = wb[wb.sheetnames[0]]
_cell = ws.cell(1,1)
_cell.number_format = '%'
_cell.value = 42 # 4200 %
_cell = ws.cell(2,1)
_cell.number_format = '%'
_cell.value = 0.42 # 42 %
wb.save("sample.xlsx")
In case you use earlier versions of openpyxel or other packages to create your excel the syntax might differ, the solution should be the same. 如果您使用openpyxel的早期版本或其他软件包创建excel,则语法可能会有所不同,解决方案应该相同。 Set a below-one float as cell value to get percentages less then 100%.
将浮点值设置为1 以下,以使百分比小于100%。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.