Message-ID: <1575805582.8225.1711638495111.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8224_490103861.1711638495111" ------=_Part_8224_490103861.1711638495111 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Number Formats

Number Formats

A number format is a string that is used to format dates or numbers= . For example, if you enter the value 0.563 in cell A4 and the number forma= t string assigned to cell A4 is "0.00%", the value displayed will= be 56.30%. Changing a cell's number format will not change the actual valu= e that is used in calculations. In Microsoft Excel, you will see the cell's= actual value in the formula bar.

Number Formats in Excel

In Excel, number formats can be assigned to cells through the Fo= rmat Cells dialog. To apply a new number format to cells in Excel:=

  1. Select a cell or group of cells.
  2. From the Format menu, select Cells, o= r, right-click the highlighted cells and select Format Cells.
  3. Select the Number tab.
  4. Select a number format category from the list on the left.
  5. Set additional attributes (if available) on the right and click Ok.

How to Set Nu= mber Formats with ExcelWriter

To assign a number format with ExcelWriter's ExcelApplication, use the Style<= /a> object's NumberFormat p= roperty. The following lines create a percentage style and assign it to a c= ell:

=20
ExcelApplication xla =3D new ExcelApplication();
Workbook wb =3D xla.Create(ExcelApplication.FileFormat.Xlsx);

//--- Create a percentage style and assign
//--- a number format to it.
GlobalStyle stylPercent =3D wb.CreateStyle();
stylPercent.NumberFormat =3D "0.00%";

//--- Assign a numeric value and
//--- stylPercent to cell A4 to display
//--- 56.30% in the cell.
ws.Cells["A4"].Value =3D "0.563";
ws.Cells["A4"].Style =3D stylPercent;
=20

ExcelWriter includes a set of built-in format constants to help you quic= kly assign commonly used display formats. For example, the constant NumberF= ormat.DateFormat.DayOfWeekMonthDayYear represents the format string "d= ddd, mmmm dd, yyyy". The following assigns this format to a date style= :

=20
GlobalStyle styleDate =3D wb.CreateStyle();
styleDate.NumberFormat =3D NumberFormat.DateFormat.DayOfWeekMonthDayYear;
=20

For a complete list of number format constants, see The NumberFormat Object.

The NumberFormat Object

The NumberFormat object is a h= elper class that you can use to create custom number format strings. Number= Format contains methods for creating accounting, currency, fraction, number= , percentage, and scientifice display formats. For example, the method Numb= erFormat.CreateAccounting creates an accounting format string. This method = takes three parameters:

numDecimalPlaces

The number of decimal places to display.

<= /td>

useDollarSign

If true, the dollar sign will be displayed.

negativeColor

A color to use when displaying negative numbe= rs. This parameter may be null.

The following example creates an accounting style with two decimal place= s, a dollar sign and negative values in red:

=20
ExcelApplication xla =3D new ExcelApplication();
Workbook wb =3D xla.Create(ExcelApplication.FileFormat.Xlsx);

GlobalStyle stylCurrency =3D wb.CreateStyle();
NumberFormat numFormat =3D wb.NumberFormat;
String acctFormat =3D numFormat.CreateAccounting(2, true, NumberFormat.Colo=
r.Red);
stylCurrency.NumberFormat =3D acctFormat;

Area ar =3D wb.Worksheets[0].CreateArea("B7:H24");
ar.ApplyStyle(stylCurrency);
=20
------=_Part_8224_490103861.1711638495111--