Excel Number Format Builder - Community / GemBox.Spreadsheet Feature Request - GemBox Support Center

Excel number format strings are cryptic; but there are smallish number of common ones that are accessible via the toolbar (e.g., Accounting or Percent). It would be really handy to have a builder class for these things in GemBox.Spreadsheet. I've started cobbling together a class of my own, with methods such as the ones below. I feel like I've got to be reinventing some wheels here; but I haven't turned up anything on the Web....

 

// e.g., 12,345.67, (12,345.67), -
public static string Accounting(int numDecs)
{
    return String.Format("_(* #,##0{0}_);_(* \\(#,##0{0}\\);_(* \"-\"??_);_(@_)", DecimalPlaceholder(numDecs));
}
// e.g., 12.3%, -12.3%, 0.0%
public static string Percent(int numDecs)
{
    return String.Format("0{0}%", DecimalPlaceholder(numDecs));
}
// Generates "", ".0", ".00", etc. depending on numDigits.
private static string DecimalPlaceholder(int numDigits)
{
    var fmt = numDigits > 0 ? "." : "";
    while (numDigits-- > 0)
    {
        fmt += "0";
    }
    return fmt;
}

Comments(2)

Dean Kopesky
// Simpler implementation of DecimalPlaceHolder() ...
private static string DecimalPlaceHolder(int numDecs){
return numDecs <= 0 ? "" : ("." + new string('0', numDecs));
}
Mario - GemBox
Hi,

This feature request has been implemented and is available in latest versions of GemBox.Spreadsheet.

Regards,

Mario
GemBox d.o.o.