IRONSOFTWAREHOME
Excel Number Format
using IronXL;
using System;
using System.Linq;

// Load an existing WorkSheet
WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();

// Set data display format to cell
// The cell value will look like 12300%
workSheet["A2"].Value = 123;
workSheet["A2"].FormatString = "0.0%";

// The cell value will look like 123.0000
workSheet["A2"].First().FormatString = "0.0000";

// Set data display format to range
DateTime dateValue = new DateTime(2020, 1, 1, 12, 12, 12);
workSheet["A3"].Value = dateValue;
workSheet["A4"].First().Value = new DateTime(2022, 3, 3, 10, 10, 10);
workSheet["A5"].First().Value = new DateTime(2021, 2, 2, 11, 11, 11);

var range = workSheet["A3:A5"];

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

workBook.SaveAs("numberFormats.xls");
Imports IronXL
Imports System
Imports System.Linq

' Load an existing WorkSheet
Dim workBook As WorkBook = WorkBook.Load("sample.xls")
Dim workSheet As WorkSheet = workBook.WorkSheets.First()

' Set data display format to cell
' The cell value will look like 12300%
workSheet("A2").Value = 123
workSheet("A2").FormatString = "0.0%"

' The cell value will look like 123.0000
workSheet("A2").First().FormatString = "0.0000"

' Set data display format to range
Dim dateValue As DateTime = New DateTime(2020, 1, 1, 12, 12, 12)
workSheet("A3").Value = dateValue
workSheet("A4").First().Value = New DateTime(2022, 3, 3, 10, 10, 10)
workSheet("A5").First().Value = New DateTime(2021, 2, 2, 11, 11, 11)

Dim range = workSheet("A3:A5")

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

workBook.SaveAs("numberFormats.xls")
NuGet Download
PM > Install-Package IronXL.Excel
Excel Number Format

Excel Number Format

We can use the FormatString property to format the display value of any Excel Cell or Range in C# with IronXL.

Using workSheet["A2"] will only select the Range of the specified address. To access a Cell, the First() method can be used. However, the FormatString property can be set directly from both Cell and Range. Therefore, the First() method can often be omitted. More Excel number formats can be applied using the same method as shown in the code example below.

In this code example, the IronXL library is used to manipulate Excel files. The WorkBook.Load method loads an existing Excel file, and the workSheet["A2"] syntax selects a specific cell within the worksheet to apply formatting. The FormatString property is then set to "0.00" to ensure that the cell value is displayed with two decimal places. Finally, workbook.SaveAs saves the modified workbook to a new file.

Learn to Set Excel Cell Data Formats with C#.
View on GitHub

Ready to Get Started?

Nuget Downloads 2,237,574Version: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