We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Export to Excel fails because of Decimal Format conversion error

I'm using syncfusion version 15.1.41 (javascript) and 15.1600.0.41 (EJ and EJ Export)
When clicking on the Grid export Excel button I get a server side Exception :

StackTrace "   at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)\r   at System.Decimal.ToString(String format, IFormatProvider provider)\r   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)\r   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)\r   at System.String.Format(IFormatProvider provider, String format, Object[] args)\r   at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordCell(Object row, Column column)\r   at System.Collections.Generic.List`1.ForEach(Action`1 action)\r   at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordRow(Object row)\r   at Syncfusion.EJ.Export.GridExcelExport.RenderRecord()\r   at Syncfusion.EJ.Export.GridExcelExport.IterateElements()\r   at Syncfusion.EJ.Export.GridExcelExport.ExportHandler()\r   at Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, Object dataSource)\r   at summer_game_2017.Controllers.GameController.ExportToExcel(String GridModel) in C:\\Projets\\test\\test\\Controllers\\GameController.cs:line 59\r   at lambda_method(Closure , Object , Object[] )\r   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()" string

System.FormatException : 'Format specifier was invalid.'
+ $exception {System.FormatException: Format specifier was invalid.
   at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)
   at System.Decimal.ToString(String format, IFormatProvider provider)
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordCell(Object row, Column column)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordRow(Object row)
   at Syncfusion.EJ.Export.GridExcelExport.RenderRecord()
   at Syncfusion.EJ.Export.GridExcelExport.IterateElements()
   at Syncfusion.EJ.Export.GridExcelExport.ExportHandler()
   at Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, Object dataSource)
   at summer_game_2017.Controllers.GameController.ExportToExcel(String GridModel) in C:\Projects\test\test\Controllers\GameController.cs:line 59
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()} System.FormatException


1 Reply

MS Mani Sankar Durai Syncfusion Team April 18, 2017 01:11 PM UTC

Hi Romain, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and we suspect that you are trying to set the decimal format for the grid column value while exporting. Normal in grid we have set the formats based on Jquery Globalization. Based on that the format value will set for the grid column value. Here {0:D} format in jquery globalize will tends to date format. So to set the decimal point for the grid column value we suggest you to set the Format as {0:N2} property of columns in grid. 
Refer the code example. 
<ej-grid id="FlatGrid" allow-sorting="true" allow-paging="true"> 
     <e-columns> 
        <e-column field="Freight" header-text="Freight" format="{0:N2}" text-align=Right width="75"></e-column> 
        ... 
    </e-columns> 
</ej-grid> 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 


Loader.
Live Chat Icon For mobile
Up arrow icon