Setting the display formats of numeric values in cell is a wonderful feature of Microsoft Excel. Add numeric data can be used to represent different values including decimal, currency, percentage, fraction or accounting values etc. All these numerical values are displayed in different formats depending on the type of information it represents. XsExcel SDK supports this functionality and allows developers to set any customized display format for a number in C# programming.

This guide page provides C# users with how to format number in cell in spreadsheet using XsExcel control for C#.NET.


// Create a new excel workbook
Workbook workBook = new Workbook();
// Create a new worksheet from workbook
Sheet sheet = workBook.CreateSheet();

// Create a new row at first line
Row row = sheet.CreateRow(0);
// Create a numeric cell
Cell cellNumeric = row.CreateCell(0);
cellNumeric.SetValue(123, "##0");
//cellNumeric.SetValue(123.12, "##0.##");
//cellNumeric.SetValue(123.123, "##0.##");
//cellNumeric.SetValue(123.123, "000");
          
// Save and show the spreedsheet
if (File.Exists("sample.xlsx")) File.Delete("sample.xlsx");
workBook.Save("sample.xlsx");
Process.Start("sample.xlsx");

Notice - If you used the trial version of XsExcel SDK, can only edit, insert or get the first 300 row data!

More Excel tutorial