workflow - ExcelNumberFormat 1.0.3

.NET library to parse ECMA-376 number format strings and format values like Excel and other spreadsheet softwares.

PM> Install-Package ExcelNumberFormat -Version 1.0.3 -Source https://www.myget.org/F/workflow/api/v3/index.json

Copy to clipboard

> nuget.exe install ExcelNumberFormat -Version 1.0.3 -Source https://www.myget.org/F/workflow/api/v3/index.json

Copy to clipboard

> dotnet add package ExcelNumberFormat --version 1.0.3 --source https://www.myget.org/F/workflow/api/v3/index.json

Copy to clipboard
<PackageReference Include="ExcelNumberFormat" Version="1.0.3" />
Copy to clipboard
source https://www.myget.org/F/workflow/api/v3/index.json

nuget ExcelNumberFormat  ~> 1.0.3
Copy to clipboard

> choco install ExcelNumberFormat --version 1.0.3 --source https://www.myget.org/F/workflow/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "workflow" -SourceLocation "https://www.myget.org/F/workflow/api/v2"
Install-Module -Name "ExcelNumberFormat" -RequiredVersion "1.0.3" -Repository "workflow" 
Copy to clipboard

ExcelNumberFormat

.NET library to parse ECMA-376 number format strings and format values like Excel and other spreadsheet softwares.

Build status

Install via NuGet

If you want to include ExcelNumberFormat in your project, you can install it directly from NuGet

To install ExcelNumberFormat, run the following command in the Package Manager Console

PM> Install-Package ExcelNumberFormat

Usage

var format = new NumberFormat("#.##");
Console.WriteLine(format.Format(1234.56, CultureInfo.InvariantCulture));

Features

  • Parses and formats most custom number formats as expected: decimal, percent, thousands, exponential, fraction, currency, date/time, duration, text.
  • Supports multiple sections with conditions.
  • Formats values with relevant constants from CultureInfo.
  • Supports DateTime, TimeSpan and numeric values for date and duration formats.
  • Supports both 1900- and 1904-based numeric datetimes (Excel on Mac uses 1904-based dates).
  • Targets net20 and netstandard1.0 for max compatibility.

Formatting .NET types

The Format() method takes a value of type object as parameter. Internally, the value is cast or converted to a specific .NET type depending on the kind of number format:

Format Kind Example .NET type Conversion strategy
Number 0.00 double Convert.ToDouble()
Fraction 0/0 double Convert.ToDouble()
Exponent #0.0E+0 double Convert.ToDouble()
Date/Time hh:mm DateTime ExcelDateTime.TryConvert()
Duration [hh]:mm TimeSpan Cast or TimeSpan.FromDays()
General General (any) CompatibleConvert.ToString()
Text ;;;"Text: "@ string Convert.ToString()

In case of errors, Format() returns the value from CompatibleConvert.ToString().

CompatibleConvert.ToString() formats floats and doubles with explicit precision, or falls back to Convert.ToString() for any other types. ExcelDateTime.TryConvert() uses DateTimes as is, or converts numeric values to a DateTime with adjustments for legacy Excel behaviors.

TODO/notes

  • 'General' is formatted with .ToString() instead of Excel conventions.
  • No errors: Invalid format strings and incompatible input values are formatted with .ToString().
  • No color information.
  • Variable width space is returned as regular space.
  • Repeat-to-fill characters are printed once, not repeated.
  • No alignment hinting.
  • No date conditions.
  • .NETFramework 2.0
  • .NETStandard 1.0
    • NETStandard.Library (>= 1.6.1)
  • .NETFramework 2.0: 2.0.0.0
  • .NETStandard 1.0: 1.0.0.0

Owners

Toma Bogdan flaviusm

Authors

ExcelNumberFormat developers

Project URL

https://github.com/andersnm/ExcelNumberFormat

License

Unknown

Tags

excel,formatting,numfmt,formatcode

Info

191439 total downloads
74858 downloads for version 1.0.3
Download (28.92 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.10 44.23 KB Thu, 17 Jun 2021 11:12:35 GMT 116581
1.0.3 28.92 KB Thu, 17 Jun 2021 08:07:01 GMT 74858