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");
More Excel tutorial
- .NET sample for converting datatable to XLSX
- How to use XsExcel DLL for .NET to load Workbook in Visual Studio .NET framework
- Excel numeric data formatted - Visual Studio .NET framework sample
- CSharp .NET online demo for converting datatable to worksheet
- How to update Excel data in Azure cloud service using C#