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

Export column correct format

Hello. I have a question that I can't understand.

I am exporting several similar datagrids (they all have the "netprice" column) and in their columns there is one that is of type "currency" and the Excel result in some cases is text and others of the correct type, which is currency.


The difference is between these two cases:

1-

public double? NetPrice { get; set; }

Result: (not sum !!! ? why????)

Captura de pantalla 2022-10-12 060243.jpg

2-

public int NetPrice { get; set; }

Result:

Captura de pantalla 2022-10-12 060352.jpg


This is the columns add for the cols:

Captura de pantalla 2022-10-12 060458.jpg

Why is the result different if both columns are numeric (int & double)?

Is it possible to solve it or should I use the export events to format or is it not necessary?

``private void Options_CellExporting(object sender, DataGridCellExcelExportingEventArgs e)

{

if (e.CellType == ExportCellType.RecordCell)

{

if (e.ColumnName is "PriceNet")

{

// ???????

}

}

}



*another question: 

I have some columns that do not show data from the observable list but that I modify through:

if(list.Name == "next")

e.DisplayText = "hello";

I need the excel column to show "hello" and not "next" in the exported excel result. Any idea how to do it?


4 Replies 1 reply marked as answer

RS Rajapandiyan Settu Syncfusion Team October 14, 2022 08:06 AM

Hi Sergio,


Thanks for contacting Syncfusion support.

In EJ2 Grid, all the data actions like formatting, sorting, filtering, etc., are performed based on the column’s field name and its type. We suggest you to manually set the column type as number which will resolve this.


columnType: https://ej2.syncfusion.com/documentation/api/grid/columnType/ 


    { field: 'Freight', width: 120, type: 'number', format: 'C2' },

    {

      field: 'Cost',

      type: 'number',

      width: 140,

      format: 'N',

    }

 


sample: https://stackblitz.com/edit/otvxpw?file=index.js

Still, if you face the same issue kindly share the below details to validate further.


  1. Share the complete code file you have used.
  2. Which type of framework you have used?
  3. Are you facing the issue with EJ2 Grid or any other component?
  4. If possible, share the issue reproducible sample with us.


By using excelQueryCellInfo event, you can customize the value before exporting the data.


excelQueryCellInfo: https://ej2.syncfusion.com/javascript/documentation/api/grid/#excelquerycellinfo



function excelQueryCellInfo(args) {

  if (args.column.field == 'ShipCountry') {

    args.value = 'Hello';

  }

}

 


Regards,

Rajapandiyan S
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



SA Sergio Ayala replied to Rajapandiyan Settu October 14, 2022 09:30 AM

the question is for winform+sfdatagrid not js...



DM Dhanasekar Mohanraj Syncfusion Team October 17, 2022 10:02 AM

Hi Sergio,

We have checked the reported issue on our end. But we are unable to reproduce the reported issue, here we have attached the tested sample for your reference. In that, we have exported the grid which contains two different currency columns with different datatypes as you mentioned. The summaries are exported properly as expected. Please have a look at this, if you still facing the reported issue please modify the attached sample based on your scenario. Or if we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further.

Regards,

Dhanasekar M.


Attachment: SfDatagridDemo_f6e1f0eb.zip


SA Sergio Ayala November 15, 2022 09:38 AM

 e.ExportMode = ExportMode.Text;


Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon