Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 'format cells' with openpyxl?

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

Example Sheet:

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

Output '6.24333E+11'

Wanted Output '62433323422'

like image 336
John Zapanta Avatar asked Sep 03 '25 03:09

John Zapanta


1 Answers

Try

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()

Adapt it as needed.

like image 136
sancho.s ReinstateMonicaCellio Avatar answered Sep 06 '25 06:09

sancho.s ReinstateMonicaCellio