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
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:=
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:
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= :
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 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.= p> |
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:
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