Export boolean fields as numbers

I'm trying to export my grid as CSV and I want to have the boolean values of my fields as 1 and 0 instead of TRUE and FALSE.
How do I achieve that?


1 Reply

RN Rahul Narayanasamy Syncfusion Team April 16, 2020 11:19 AM UTC

Hi Andreas, 

Greetings from Syncfusion support.  

Query: “Is there a way in the ExcelExportProperties to take what's being displayed in the grid rather than the raw data? 

We have validated your query and yes, we can achieve your requirement by assigning the custom data source to DataSource property of ExcelExportProperties. Refer the below code example.  

. . . 
public void CSVExport() 
    { 
        List<CustomOrder> CustomData = new List<CustomOrder>(); 
        foreach (var ord in Orders) 
        { 
            CustomData.Add(new CustomOrder() { OrderID = ord.OrderID, CustomerID = ord.CustomerID, Freight = ord.Freight, OrderDate = ord.OrderDate, Verified = ord.Verified ? 1 : 0 }); 
        } 
        ExcelExportProperties ExportProperties = new ExcelExportProperties(); 
        ExportProperties.DataSource = CustomData; 
        this.DefaultGrid.CsvExport(ExportProperties); 
    } 

Note:  While exporting alone we have assigned custom data converting the bool to int. it is will assigned only while exported. Orignial data source will not be affected. In similar way you can modify your bool value as true – 1 and false – 0. 

For your convenience  we have prepared a sample which can be downloaded from below  

Reference: 

Kindly get back to us if you have further queries.  

Regards, 
Rahul 


Loader.
Up arrow icon