IRONSOFTWAREHOME
Excel Number Format
from ironxl import *

# Load an existing WorkSheet
workbook = WorkBook.Load("sample.xls")
worksheet = workbook.WorkSheets[0]

# Set data display format to range
worksheet["A3"].Value = DateTime(2020, 1, 1, 12, 12, 12)
worksheet["A4"].Value = DateTime(2022, 3, 3, 10, 10, 10)
worksheet["A5"].Value = DateTime(2021, 2, 2, 11, 11, 11)

selected_range = worksheet["A3:A5"]

# The cell(A3) value will look like 1/1/2020 12:12:12 PM
selected_range.FormatString = "MM/dd/yy h:mm:ss"

# Save changes with applied number formats
workbook.SaveAs("numberFormats.xls")
pip install ironxl
Excel Number Format

Excel Number Format

Use the FormatString property to control how numeric values are displayed in any Excel Cell or Range with IronXL for Python.

Using worksheet["A2"] selects the Range for the specified address. To access an individual Cell, the First() method can be used. However, the FormatString property can be set directly on both a Cell and a Range, so First() can often be omitted. Additional number formats can be applied using the same approach, as demonstrated in the code example below.

In the code example, the WorkBook.Load method opens an existing Excel file. The worksheet["A2"] syntax selects a specific cell, and the FormatString property is set to "0.00" to display the value with two decimal places. Finally, SaveAs method saves the modified workbook to a new file.

Learn to Set Excel Cell Data Formats with Python.

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required