Simplexcel icon indicating copy to clipboard operation
Simplexcel copied to clipboard

Currency Support

Open fmillerr opened this issue 4 years ago • 1 comments

I see no way in defining a cell as a currency cell. Would be nice if there was a way.

fmillerr avatar Mar 29 '21 09:03 fmillerr

Probably the xlsx doesn't have a "currency" cell type, but you can do that by using a format. This is how I create mine to write currency values:

static string GetExcelFormat(string symbol, double value)
{
    var customCulture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
    customCulture.NumberFormat.CurrencySymbol = symbol;
    cFormat = value.ToString("C2", customCulture);
    var nFormat = value.ToString("N2");
    if (cFormat.Contains(nFormat) && cFormat.Contains(symbol))
    {
          return cFormat.Replace(nFormat, "#,##0.00").Replace(symbol, "[$" + symbol + "]");
    }
    return "#,##0.00 [$" + symbol + "]";
}

tipa avatar Mar 29 '21 13:03 tipa

https://github.com/mstum/Simplexcel/issues/43

mstum avatar Aug 25 '22 13:08 mstum