Xlibur.ExcelNumberFormat 1.2.3

dotnet add package Xlibur.ExcelNumberFormat --version 1.2.3
                    
NuGet\Install-Package Xlibur.ExcelNumberFormat -Version 1.2.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xlibur.ExcelNumberFormat" Version="1.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xlibur.ExcelNumberFormat" Version="1.2.3" />
                    
Directory.Packages.props
<PackageReference Include="Xlibur.ExcelNumberFormat" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Xlibur.ExcelNumberFormat --version 1.2.3
                    
#r "nuget: Xlibur.ExcelNumberFormat, 1.2.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Xlibur.ExcelNumberFormat@1.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Xlibur.ExcelNumberFormat&version=1.2.3
                    
Install as a Cake Addin
#tool nuget:?package=Xlibur.ExcelNumberFormat&version=1.2.3
                    
Install as a Cake Tool

Xlibur.ExcelNumberFormat

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

This library is a fork of andersnm/ExcelNumberFormat. It is published to NuGet as Xlibur.ExcelNumberFormat; the namespace is unchanged.

Credit to the original author, @andersnm, who wrote the library this is built on. The original copyright and MIT license are kept in the LICENSE file.

Install

dotnet add package Xlibur.ExcelNumberFormat

Usage

using System.Globalization;
using ExcelNumberFormat;

var format = new NumberFormat("#,##0.00");
Console.WriteLine(format.Format(1234.5, CultureInfo.InvariantCulture)); // 1,234.50

// Dates and durations
Console.WriteLine(new NumberFormat("yyyy-mm-dd hh:mm").Format(45498.5, CultureInfo.InvariantCulture)); // 2024-07-25 12:00
Console.WriteLine(new NumberFormat("[h]:mm:ss").Format(TimeSpan.FromMinutes(90), CultureInfo.InvariantCulture)); // 1:30:00

Parsing a format string costs more than formatting a value with it. If the same format strings come up again and again, for example once per cell, get them from NumberFormat.GetOrCreate(formatString), which parses each format string only the first time. A NumberFormat is immutable and safe to share between threads.

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, including empty sections such as ;;;.
  • 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).
  • Rounds like Excel: half away from zero, and fractional seconds (.0, .00, .000) are rounded and carried.
  • Targets net8.0, net10.0 and net11.0.

Formatting .NET types

Format() takes a value of type object, and has overloads for double, float, decimal, long, ulong, DateTime and TimeSpan that avoid boxing the value. Other numeric types (int, short, byte and so on) bind to the long overload. DateOnly and TimeOnly are accepted through the object overload. Internally, the value is converted to a specific .NET type depending on the kind of number format:

Format Kind Example .NET type Conversion
Number 0.00 double numeric value
Fraction 0/0 double numeric value
Exponent #0.0E+0 double numeric value
Date/Time hh:mm DateTime DateTime as is, numeric values as an Excel date serial
Duration [hh]:mm TimeSpan TimeSpan as is, numeric values as a number of days
General General (any) the value as text
Text ;;;"Text: "@ string the string

If a value cannot be formatted, for example a date format applied to a string, Format() returns the value as plain text instead of throwing.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Xlibur.ExcelNumberFormat:

Package Downloads
XLibur

See release notes https://github.com/XLibur/XLibur/releases/tag/v0.800.0 XLibur is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.3 1,366 10/31/2026
1.2.2 85 10/30/2026
1.2.1 103 10/30/2026
1.2.0 85 10/30/2026
0.0.0-alpha.48 65 10/30/2026