简体   繁体   English

我想用“%”号显示我的EXCEL数据。 我如何使用python做到这一点

[英]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.

相关问题 Jupyter笔记本中python 3中的标识符中的无效字符,箭头指向负号。 我的清单中可以没有否定词吗? - invalid character in identifier in python 3 in a Jupyter notebook, arrow pointing to a negative sign. Can I not have a negative in my list? 我想提取以 $ 符号开头的数字。 例如:545 美元 - I want to extract numbers which are started with $ sign. for ex: $545 我如何告诉python我的数据结构(二进制)是什么样子,以便我可以绘制它? - How do I tell python what my data structure (that is in binary) looks like so I can plot it? 我该如何修正我的代码,以便它可以打印出我想要的结果? - How Do I Fix My Code So It Can print() Out The Results I Want? 如何编辑我的 VS Code 环境,以便我可以为我的 Python 代码预设输入数据,这样我就不必一次又一次地输入数据 - How do I edit my VS Code environment so that I can preset Input data for my Python Code so that I don't have to input data again and again 我如何继续循环我的程序,以便用户可以输入尽可能多的内容? - How do i keep looping the same my program so the user can input as much as they want? 尝试以 json 格式对我的数据进行分析。 到目前为止,我的代码下面我的问题是如何加入我的所有数据,请帮助我是 Python 新手 - trying do analysis to my data in json format. my code below so far my questions is how can I join all my data , pls help I am new to python 我的文本文件在键值对中有数据,我想使用 python 将其移动到 excel - My text file has data in key value pair and i want to move it to excel using python Excel 到 JSON 使用 Python,我如何根据需要格式化此数据? - Excel to JSON using Python, how do I format this data to my needs? 如何配置python脚本的路径,以便可以使用cmd和python解释器打开它 - How do I configure the path of my python scripts so I can open it with cmd and python interpreter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM