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 personalized boolean values

Hello.
I have a grid that shows data that include a boolean column which is displayed in the grid as a checkbox (perfect behaviour for me).
But when I export the grid to Excel or Pdf, the boolean values are shown as "Verdadero" or "Falso" (in Spanish). I would like to customize these values to show whatever I like (for example Ok/No Ok or Sí/No) ONLY in the exported document.
I have even tried to use a template for the column. I got the desired results on the web page but in the Excel file were shown again the unwanted values.
Any way to achieve this?
Thanks in advance.


3 Replies

VN Vignesh Natarajan Syncfusion Team May 2, 2019 05:33 AM UTC

Hi Toni,  
 
Thanks for contacting Syncfusion support.  
 
Query: “ would like to customize these values to show whatever I like (for example Ok/No Ok or Sí/No) ONLY in the exported document 
 
From your query, we understand that you need to customize the value while exporting. We suggest you to achieve your requirement using server events (OnServerExcelQueryCellInfo and OnServerPdfQueryCellInfo). Please refer the below code example 
 
<ej:Grid ID="FlatGrid" runat="server" IsResponsive="true"  AllowFiltering="True" AllowGrouping="true" AllowReordering="true" AllowSorting="true" OnServerExcelQueryCellInfo="FlatGrid_ServerExcelQueryCellInfo" OnServerPdfQueryCellInfo="FlatGrid_ServerPdfQueryCellInfo" OnServerWordExporting="FlatGrid_ServerWordExporting" OnServerPdfExporting="FlatGrid_ServerPdfExporting" OnServerExcelExporting="FlatGrid_ServerExcelExporting" AllowPaging="True"> 
            <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport,wordExport,pdfExport"></ToolbarSettings> 
       <Columns> 
…………………………………….. 
           <ej:Column Field="Verified" HeaderText="True/False" Width="90" /> 
             </Columns>             
        </ej:Grid> 
 
///////////////////////////// 
 
protected void FlatGrid_ServerExcelQueryCellInfo(object obj) 
        { 
            IRange range = (IRange)obj; 
            if ( range.Column == 7) 
            { 
                if (range.Value == "TRUE") 
                    range.Value = "Ok"; 
                else 
                    range.Value = "Not Ok"; 
 
            }                 
        } 
 
 
////////////////////////////// 
 
protected void FlatGrid_ServerPdfQueryCellInfo(object obj) 
        { 
            PdfGridCell gCell = (PdfGridCell)obj; 
            if (gCell.Value.ToString() == "true") 
                gCell.Value = "Ok"; 
            else if (gCell.Value.ToString() == "false") 
                gCell.Value = "Not Ok"; 
        }         
 
 
Refer the below screeshot for the output 
 
  1. Excel File
 
 
 
  1. Pdf file
 
 
 
For your convenience we have prepared a sample which can be downloaded from below link 
 
 
Refer our UG document for your reference 
 
  
 
Please get back to us if you have further queries. 
 
Regards, 
Vignesh Natarajan.  



TM Toni Moreno May 2, 2019 10:30 AM UTC

The solution is good but still does not fullfill my needs.
In your sample you use "if ( range.Column == 7)" to change the value but my grid has a column chooser and could happen that the column is not always in the same position.
Can I check if is the right column by column name or something like that?
Thanks


VN Vignesh Natarajan Syncfusion Team May 3, 2019 05:27 AM UTC

Hi Toni, 
 
Thanks for the update. 
 
Query: Can I check if is the right column by column name or something like that? 
 
As per your requirement we have achieved your requirement by changing the text using columnName in the server side events. We have also ensured the solution using columnChooser. Refer the below code example, 
 
 
<ej:Grid ID="FlatGrid" runat="server" IsResponsive="true"  ShowColumnChooser="true" AllowFiltering="True" AllowGrouping="true" AllowReordering="true" AllowSorting="true"  OnServerExcelRowInfo="FlatGrid_ServerExcelRowInfo" OnServerPdfRowInfo="FlatGrid_ServerPdfRowInfo" OnServerPdfExporting="FlatGrid_ServerPdfExporting" OnServerExcelExporting="FlatGrid_ServerExcelExporting" AllowPaging="True"> 
            <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport,pdfExport"></ToolbarSettings> 
       <Columns> 
………………………………. 
             </Columns>             
        </ej:Grid> 
 
 
// Server End 
 
public GridProperties obj; 
 
List<cols> column = new List<cols>(); 
 
  protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) 
        { 
            ExcelExport exp = new ExcelExport(); 
            obj = ConvertGridObject(e.Arguments["model"].ToString()); 
            GridExcelExport exp1 = new GridExcelExport() { Theme = "flat-lime", FileName = "Export.xlsx" }; 
            exp.Export(obj, (IEnumerable)FlatGrid.DataSource, exp1); 
        } 
 
        protected void FlatGrid_ServerPdfExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) 
        { 
            PdfExport exp = new PdfExport(); 
            obj = ConvertGridObject(e.Arguments["model"].ToString()); 
            GridPdfExport exp1 = new GridPdfExport() { Theme = "flat-lime", FileName = "Export.pdf" }; 
            exp.Export(obj, (IEnumerable)FlatGrid.DataSource, exp1); 
        } 
 
        private GridProperties ConvertGridObject(string gridProperty) 
        { 
           ………….. 
       } 
 
         
        protected void FlatGrid_ServerExcelRowInfo(object currentCell) 
        { 
            GridColumnChange(); 
            IRange range = (IRange)currentCell; 
            for (var y = 0; y < range.Column; y++) 
            { 
                if (column[y].Field == "Verified"// Check the Boolean values field name and apply the customization. 
                { 
                    if (range.Value == "TRUE") 
                        range.Value = "Ok"; 
                    else 
                        range.Value = "Not Ok"; 
                } 
            } 
        } 
 
 
        protected void FlatGrid_ServerPdfRowInfo(object currentCell) 
        { 
            GridColumnChange(); 
            Syncfusion.Pdf.Grid.PdfGridRow range = (Syncfusion.Pdf.Grid.PdfGridRow)currentCell; 
            for (var i = 0; i < range.Cells.Count; i++) 
            { 
                if (column[i].Field == "Verified") // Check the Boolean values field name and apply the customization. 
                { 
                    if (range.Cells[i].Value.ToString() == "true") 
                        range.Cells[i].Value = "Ok"; 
                    else if (range.Cells[i].Value.ToString() == "false") 
                        range.Cells[i].Value = "Not Ok"; 
                } 
            } 
        } 
 
        public void GridColumnChange() 
        { 
            for (var j = 0; j < obj.Columns.Count; j++) 
            { 
                if (obj.Columns[j].Visible == true) 
                { 
                    column.Add(new cols() { Field = obj.Columns[j].Field }); // Add Visible column Field here. 
                } 
 
            } 
        } 
 
        public class cols 
        { 
            public string Field { get; set; } 
            
        } 
 
 
 
For your convenience we have prepared a sample which can be downloaded from below 
 
 
Please get back to us, if you need further assistance. 
 
Regards, 
Vignesh Natarajan. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon