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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Export grid excel with numeric format

Thread ID:

Created:

Updated:

Platform:

Replies:

125592 Aug 26,2016 10:57 AM UTC Aug 30,2016 08:38 AM UTC ASP.NET Web Forms 3
loading
Tags: Grid
Manolo
Asked On August 26, 2016 10:57 AM UTC

Hi,

I can export a grid in excel, but I need that some columns have a numeric cell style.

For example:

Complementaria Column has cell format numeric with thousand separator (I set it manually) but Anomalias column has general format. How can I set the numeric format (in function of region's user) when I export a grid?



Thanks

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 29, 2016 09:56 AM UTC

Hi Manolo, 

We suspect that you would like to apply locale and follow your preferred culture for the Numeric column while exporting the Grid.  

This can be achieved by mentioning the Locale (any preferred culture) to the Grid and defining the numeric format for the corresponding column. Refer to the following code example and the exported Grid. 

    <ej:Grid ID="OrdersGrid" runat="server" Locale="ca-ES" OnServerWordExporting="OrdersGrid_ServerWordExporting" OnServerPdfExporting="OrdersGrid_ServerPdfExporting" OnServerExcelExporting="OrdersGrid_ServerExcelExporting" AllowPaging="True"> 
        <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport,wordExport,pdfExport"></ToolbarSettings> 
        <Columns> 
            <ej:Column Field="OrderID" HeaderText="Order ID" /> 
            <ej:Column Field="CustomerID" HeaderText="Customer ID" /> 
            <ej:Column Field="EmployeeID" HeaderText="Employee ID" /> 
            <ej:Column Field="Freight" HeaderText="Freight" Format="{0:N}" /> 
        </Columns> 
    </ej:Grid> 
 
        protected void OrdersGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) 
        { 
            ExcelExport exp = new ExcelExport(); 
            exp.Export(OrdersGrid.Model, (IEnumerable)OrdersGrid.DataSource, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime"); 
        } 

 

Note: To use the Localization in Grid, you have to refer the preferred ej culture script in your application as shown in the following table. 

<head runat="server"> 
    <link rel='nofollow' href="Content/ej/web/flat-lime/ej.widgets.all.min.css" rel="stylesheet" /> 
           . . .  
    <script src="Scripts/ej/ej.web.all.min.js"></script> 
    <script src="Scripts/ej/ej.culture.ca-ES.min.js"></script> 
    <script src="Scripts/ej/ej.webform.min.js"></script> 
 
</head> 

We have prepared a sample that can be downloaded from the following location. 


Refer to the following Help Documents. 


Regards, 
Seeni Sakthi Kumar S. 


Manolo
Replied On August 29, 2016 10:26 AM UTC

Hi,

I'm using the syncfusion version 14.2451.0.26. In your example, when I export, the thousand separator is not applied.



I need update or set other config?

Thanks

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 30, 2016 08:38 AM UTC

Hi Manolo, 

We suspect the cause of the problem is difference in time zone and location settings of the machine. To overcome this problem we suggest to format the cell value using the following code example. 

        protected void OrdersGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) 
        { 
            ExcelExport exp = new ExcelExport(); 
            OrdersGrid.Model.ServerExcelQueryCellInfo = querycell; 
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ca-ES");  
            exp.Export(OrdersGrid.Model, (IEnumerable)OrdersGrid.DataSource, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime"); 
        } 
        public void querycell(object sender) 
        { 
            var data = (IRange)sender; 
            if (data.Column == 3) //Frieght or numeric column 
            { 
                data.NumberFormat = "#.##0,00"; 
            } 
        } 

ServerExcelQueryCellInfo is the side server-side events where you can format the value of the cells. 

We have also modified the sample that can be downloaded from the following location. 


Refer to the Help document for the Export Server events.    


Regards, 
Seeni Sakthi Kumar S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;