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

Excel Export from a RadGrid

3 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bernard
Top achievements
Rank 1
Bernard asked on 15 Dec 2014, 03:15 PM
Hi,

I use an Excel Export from a RadGrid.
I would like to replace an image by a text.

This code worked fine before.
But it doesn't work any more since the last update or the previous one.is it the good way to do this ?

Many thanks for your help,
Bernard
...
aRadGrid.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.Semicolon;
            aRadGrid.ExportSettings.FileName = aFileName;
            aRadGrid.ExportSettings.HideStructureColumns = true;
            aRadGrid.ExportSettings.ExportOnlyData = true;
            aRadGrid.ExportSettings.IgnorePaging = true;
            aRadGrid.ExportSettings.OpenInNewWindow = true;

private void Export()
        {
            ((GridClientSelectColumn)aRadGrid.MasterTableView.GetColumn(XarcT.UN_S)).Visible = false;
            foreach (GridDataItem item in aRadGrid.Items)
            {
                if (item.ItemType == GridItemType.AlternatingItem)
                {
                    item.BackColor = Color.LightGray;
                };
                TableCell cell = (TableCell)item[XarcT.UN_L];
                bool aBool = (cell.Text == @"True");
                cell = (TableCell)item[XarcT.UN_Limg];
                cell.Text = (aBool ? @"L" : null);
            };
           if (dataContainer.xarcUaLstPrm.currentAction == XarcUaLstPrm.Action.Excel)
            {
                aRadGrid.MasterTableView.ExportToExcel();
            }
            else
            {
                aRadGrid.MasterTableView.ExportToCSV();
            };
        }

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 18 Dec 2014, 12:10 PM
Hello Bernard,

Based on the provided code it is rather difficult top determine what exactly is causing the issue and what can be the root for its appearance. Therefore can I kindly ask you to provide us full version of your code that we can run locally? Thus we will be able to replicate the issue and fix the problem as soon as possible.

Regards,
Maria Ilieva
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
Bernard
Top achievements
Rank 1
answered on 08 Jan 2015, 03:59 PM

Hello Maria,
I understand that it's not easy for you without a full version of code that you can run locally.
But it's difficult for me to extract a part in a smaller project.
So I'll try to rephrase my question.
I have a Radgrid and I use the function "MasterTableView.ExportToExcel()"
But before generate the Excel file, I would like to change the value of a column.
For example, I have a GridImageColumn (which represents a boolean) and I would like to replace this column by a value In the Excel file.
Is there a way to do that ?
Regards
Bernard
0
Maria Ilieva
Telerik team
answered on 13 Jan 2015, 08:11 AM
Hi Bernard,

Please try with the below code snippet.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName.Equals(RadGrid.ExportToExcelCommandName))
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            item["YourColumnUniqueName"].Text = "YourNewValue";
        }
    }
}

Using this approach you will be able to change the value before export.

Let me know if this helps.

Regards,
Maria Ilieva
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.

 
Tags
Grid
Asked by
Bernard
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Bernard
Top achievements
Rank 1
Share this question
or