Boost Fertility New Invention Ups Success Rates.pdf
C# excel set excel number style
1. C# Excel Number Style
In Excel, right-click a cell or group of cells and choosing Format Cell, a window with number
formatting options will pop up for you to choose. Number formatting is the ability to control how
a number is displayed by taking advantage of the culture-specific thousand and decimal
separators, the amount of decimals as well as a currency symbol. Number format can also be used
to format dates, percentages, and even custom formats. Through C#, programmers also can set
number styles in Excel, and even without Microsoft Excel installed on system.
How to Use C# Set Excel Number Style
Spire.XLS for .NET is .NET Excel component which enables your .NET applications fast
generate, read, write and modify Excel document without Microsoft Office Excel Automation.
With Spire.XLS, programmers can use C# set Excel number style easily.
Download Spire.XLS for .NET (or Spire.Office) with .NET Framework 2.0 (or above) together
and use the code below to set Excel number Style:
C# Excel Number Style:
01 private void ExcelDocViewer( string fileName )
02 {
03 try
04 {
05 System.Diagnostics.Process.Start(fileName);
06 }
07 catch{}
08 }
09
10 private void btnRun_Click(object sender, System.EventArgs e)
11 {
12 Workbook workbook = new Workbook();
13 Worksheet sheet = workbook.Worksheets[0];
14
15 sheet.Range["B1"].Text = "NUMBER FORMATTING";
16 sheet.Range["B1"].Style.Font.IsBold = true;
17
18 sheet.Range["B3"].Text = "0";
19 sheet.Range["C3"].NumberValue = 1234.5678;
20 sheet.Range["C3"].NumberFormat = "0";
21
22 sheet.Range["B4"].Text = "0.00";
23 sheet.Range["C4"].NumberValue = 1234.5678;
24 sheet.Range["C4"].NumberFormat = "0.00";
3. After running the code above in your application, you will get different number style as the image
below:
More about Spire.XSL
Download Spire.XSL
Purchase Spire.XLS
A short listing of the great formatting capabilities is provided below, but let's not regard it as a
replacement for the online reference Excel help on that matter.
To escape text, enclose it in quotes, like in $0.00" Surplus";$-0.00" Shortage"
To add a space character, include an _ (underscore).
Use # for insignificant digits. Using ####.#, 1234.59 displays as 1234.6
Use 0 for significant digits (or for padding). Using #.0#, 12 displays as 12.0
Use ? for alignment
Use , as thousand separator
Use . as decimal separator
Use ; to separate the formatting when the number is positive, and the formatting when the
number is not
Use [Red] to add color to a cell, as in [Red]###,###.00. Among known colors are [Red],
[Black], [Cyan], [Green], [Magenta], [Blue], [White] and [Yellow], as well as colors from the
56 predefined palette of the form [Color___] where ___ is a number between 1 and 56.
Use closed brackets to enclose conditions, or use the conditional formatting object. Example
using closed brackets : [Red][<=100];[Blue][>100]
Use % to display a number as a percentage. Please note that Excel will automatically perform
a 100 time multiplication.
4. Use the typical date symbols to format dates. Symbols can be combined as below :