Is it possible to ignore Excel warnings when generating spreadsheets using EPPlus?

前端 未结 4 419
余生分开走
余生分开走 2020-12-06 18:54

I\'m storing mix of numeric and non-numeric values in a single column in spreadsheet using C# and EPPlus. When I open spreadsheet with Excel it shows green triangles in the

4条回答
  •  情深已故
    2020-12-06 19:15

    You can check if your value is integer, convert it to int and assign number to cell's value. Then it will be saved as number, not string.

    public static void SetValueIntOrStr(this ExcelRangeBase range, object value)
    {
        string strVal = value.ToString();
        if (!String.IsNullOrEmpty(strVal))
        {
            double dVal;
            int iVal;
    
            if (double.TryParse(strVal, out dVal))
                range.Value = dVal;
            else if (Int32.TryParse(strVal, out iVal))
                range.Value = iVal;
            else
                range.Value = strVal;
        }
        else
            range.Value = null;
    }
    

提交回复
热议问题