This is a migrated thread and some comments may be shown as answers.

export boolean columns from RadGridView

10 Answers 98 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gani
Top achievements
Rank 1
Gani asked on 11 Apr 2014, 11:37 PM
My item source to grid is a class has about 20 columns. I have two bool columns.

public bool IsPassed {get;set;}
public bool HasPassport {get;set;}

when the grid is loaded or searhced these two cols display an image icon when the value is true.
while exporting to excel if IsPassed = true..then I have to show "Yes" in the excel else empty
if HasPassport = true, then I have to display some string value like "hdgfjhgh"

can anyone give me an example how to do it ?


10 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 14 Apr 2014, 08:13 AM
Hi,

To override the default export, you can subscribe for the ElementExporting event of RadGridView and set the e.Value to be exported as you would like to.

Regards,
Didie
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Gani
Top achievements
Rank 1
answered on 14 Apr 2014, 05:34 PM
we are following the MVVM Prism, here I have a button bind to viewmodel, in the viewmodel we have the access to the grid. 
Am using CSExcelExportUtilities.GetExcelMLFromGridView()
                 CSExcelExportUtilities.ExportToExcel()
this method to export to excel. 

Can I override the value here as i have access to the grid ? How to do that
0
Dimitrina
Telerik team
answered on 15 Apr 2014, 12:12 PM
Hi,

If you have access to RadGridView, then you can subscribe for its ElementExporting event. The only way to override the value that is exported is through this event (setting a proper e.Value instead the one that is coming by default). You can check our Exporting WPF Demos for some examples on how to customize the export.

Regards,
Didie
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Gani
Top achievements
Rank 1
answered on 15 Apr 2014, 04:31 PM
I want to update the content in that column, with the e.Value i can update the column header or style etc. In the grid am showing a image icon now want to convert that some string "*****" while exporting. 

Thanks
0
Dimitrina
Telerik team
answered on 18 Apr 2014, 10:13 AM
Hello,

I am not sure I understand your question. You say with the e.Value you can update the column header or style etc. Actually you can change any value that is going to be exported. Do you have a problem changing the value when you have subscribed for the ElementExporting event?

Regards,
Didie
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Gani
Top achievements
Rank 1
answered on 24 Apr 2014, 06:36 PM
Yes I have the problem , when I update the e.value it is reflected in the header. Lets say I have a column called "File"  we show a file icon in the radgrid results when it is true, while exporting to excel i want to update that to "Yes" to a string.

File || Name ||
----------------------------
Yes || xyx ||
0
Accepted
Dimitrina
Telerik team
answered on 28 Apr 2014, 10:45 AM
Hello,

In order to not override the headers you need to change the e.Value only when the e.Element is ExportElement.Cell.

For example:
private void clubsGrid_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
    if (e.Element == ExportElement.Cell)
    {
        var column = e.Context as GridViewDataColumn;
        if (column != null && column.Header.ToString()=="File")
        {
              if (e.Value == true)
              {
            e.Value = "Yes";
              }
        }
    }
 
}

 How does this work for you?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Gani
Top achievements
Rank 1
answered on 28 Apr 2014, 05:03 PM
Thanks, it worked.
0
jlj30
Top achievements
Rank 2
answered on 16 May 2016, 07:42 PM

Hi,

I have the same requirement, but am using Format="Xlsx" and trying to accomplish this same task using the OnInfrastructureExporting event handler as follows:

protected void grdUserAdmin_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
{
    var colCount = e.ExportStructure.Tables[0].Columns.Count;
    var rowCount = e.ExportStructure.Tables[0].Rows.Count;
    ExportStyle headerStyle = new ExportStyle();
    headerStyle.ForeColor = Color.White;
    headerStyle.BackColor = Color.Blue;
    headerStyle.Font.Bold = true;
 
    // Set the header style for all columns
    for (var i = 1; i <= colCount; i++)
    {
        e.ExportStructure.Tables[0].Cells[i, 1].Style = headerStyle;
        e.ExportStructure.Tables[0].Columns[i].Width = 200; // Would like auto-width !!
    }
 
    // Place an "X" in cells assigned to a boolean data field if value is true
    var headerText = "";
    for (var c = 1; c <= colCount; c++)
    {
        for (var r = 1; r <= rowCount; r++)
        {
            if (r == 1)
            {
                headerText = e.ExportStructure.Tables[0].Cells[c, r].Value.ToString();
                continue;
            }
            if (headerText == "Active")
            {
                var x = e.ExportStructure.Tables[0].Cells[c, r].Value.ToString();
                System.Diagnostics.Debug.WriteLine("Cell Value: " + x);
                if (Convert.ToBoolean(e.ExportStructure.Tables[0].Cells[c, r].Value.ToString()))
                    e.ExportStructure.Tables[0].Cells[c, r].Value = "X";
            }
        }
    }
 
}

The value for the variable x above is always "" or null (hard to tell in the Output section of VS).

I know that my data for column Active should have all true values.

The conversion to boolean fails!

I think I'm close.

What am I doing wrong?

Thanks in advance for any advice.

Jim

0
Stefan
Telerik team
answered on 18 May 2016, 03:11 PM
Hi Jim,

As this forum thread is for the Telerik UI for WPF suite, can you please repost your question in the relevant forum section which I believe is the UI for ASP.NET AJAX?

Thank you in advance for your cooperation.

All the best,
Stefan X1
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
General Discussions
Asked by
Gani
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Gani
Top achievements
Rank 1
jlj30
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or