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

Grid - Excel Export

Hello Syncfusion team,

When exporting to Excel, is it possible to set a cell on a specific type? Previously we were using some controls from another company and it was possible.

We have some columns with time (HH:mm) that were exported on 'Custom' format and now they are exported as 'Text' and it was very useful for our customers to export to Excel and directly sum this columns. 

Thanks in advance.

3 Replies

BS Balaji Sekar Syncfusion Team February 5, 2020 09:11 AM UTC

Hi Matias, 
 
Greetings from Syncfusion forum. 
 
We have validated and achieved your requirement using excelQueryCellInfo and getDateFormat method based on our assumptions. 
 
Query: it possible to set a cell on a specific type?  
 
Yes, wou can set column in specific type using  ‘type’ property in column level. 
 
 
We have applied the “Applied” Column as in HH: mm Custom format and are shown in that format. The getDateFormat method that returns a function that formats a date object based on the specified DateFormatOptions. Using this format in excelQueryCellInfo, we can export the value as in text with corresponding format options. Using this text value we can perform whatever we want. 
 
Reference links. 
 
 
 
Please refer to the below code and sample link. 
 
var intl = new ej.base.Internationalization() 
var grid = new ej.grids.Grid({ 
dataSource: data, 
  allowExcelExport: true, 
 .. . . . 
  columns: [ 
. . . . 
    { 
      field: "Applied", 
      headerText: "Order Date", 
      width: 130, 
      format: {type:'date', format:'HH:mm'}, 
      textAlign: "Right" 
    } 
  ], 
  excelQueryCellInfo: function(e) {debugger; 
  if(e.column.field === 'Applied'){ 
    var format = e.column.format; 
    var intl = new ej.base.Internationalization(); 
    var dFormatter = intl.getDateFormat(format); 
    e.value = dFormatter(e.value); 
    console.log(e.value); // returns text value  
  } 
  } 
}); 
grid.appendTo("#Grid"); 

 
 
Still, facing the issue please share the below details. 
 
  1. Structural view of your dataSource
  2. Pictorial representation of your requirement.
  3. Explain your requirement briefly.
 
Please get back to us, if you need any further assistance. 
 
Regards, 
Balaji Sekar. 



MP Matias Puzanowski February 5, 2020 12:48 PM UTC

Hello!

Thanks a lot for your response.

I'm providing an example from an Excel export of our previous grid control (Selecting 'HH:mm' cells, you are able to SUM)


And we cannot achieve this with the solution you provided:



TS Thiyagu Subramani Syncfusion Team February 12, 2020 11:22 AM UTC

Hi Matias ,  

Thanks for your update. 

We have checked issue with your reported information. In previous update value for the column “OrderDate” is passed as string(text) values instead of date time object as per your requirement. Because of this, Excel export serializes the values as string. So, the SUM action in Excel is not performed. Its default behavior of excel . So, we suggest you to set the cell value as Date time instance to make the Excel perform SUM action. In this below sample, once we reach the edit state to the corresponding exported text value cell , its act as the  default excel cell format like below image. 

 

 

   
Please let us know if you have any queries.  

Regards,  
Thiyagu S.  


Loader.
Live Chat Icon For mobile
Up arrow icon