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.
How to use Excel NumberFormat
in C#
- Download C# library to use Excel number format
- Load an existing Excel file with the
Load
method - Set the
FormatString
property of a cell to specify the number format. - Export the edited spreadsheet with the
SaveAs
method
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.
Discover How to Set Cell Data Formats in Excel Using C# with Our Detailed Guide!