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.11just released