Newer
Older
ClosedXML / ClosedXML / Extensions / FormatExtensions.cs
@Francois Botha Francois Botha on 9 Nov 2017 411 bytes Use ExcelNumberFormat library to format strings.
using ExcelNumberFormat;
using System.Globalization;

namespace ClosedXML.Extensions
{
    internal static class FormatExtensions
    {
        public static string ToExcelFormat(this object o, string format)
        {
            var nf = new NumberFormat(format);
            if (!nf.IsValid)
                return format;

            return nf.Format(o, CultureInfo.InvariantCulture);
        }
    }
}