如何使用openpyxl“格式化单元格"? [英] How to 'format cells' with openpyxl?

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

问题描述

我想使用openpyxl在excel工作表中设置列单元格的格式,使其数字的小数位数为"0".

I want to format the column cells in my excel sheet using openpyxl to have their numbers decimal places at '0'.

示例表:

     B           C
63245634566     NAME
63562341234     NAME
23452345345     NAME
21345234554     NAME
41234123442     NAME
23542345345     NAME
6.24333E+11     NAME
43242334233     NAME

输出' 6.24333E + 11 '

Output '6.24333E+11'

想要的输出' 62433323422 '

Wanted Output '62433323422'

推荐答案

尝试

from openpyxl import load_workbook
wb = load_workbook( 'so_12387212.xlsx' )
ws = wb[ wb.sheetnames[0] ]
cell11 = ws.cell(1, 1)
cell11.number_format = '0'
wb.save( 'so_12387212.xlsx' )
wb.close()

根据需要进行调整.

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

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