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

Export to Excel- Want to export cell data not bount column

2 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Winni
Top achievements
Rank 1
Winni asked on 06 Sep 2011, 07:48 AM

Hi,

I need to export radgrid to CSV and Excel as well as print .One particular column of the grid is a  datetime column .But in the grd_DataBound event I am changing the value of that field to either Y or null for business purpose(e.Item.Cells[4].Text = "Y";).

 This is only for showing to the user and the column is bound to datetime field.

 While exporting CSV exports the Y or null but excel exports the date time value. While print also I am getting Y or null value.

Could anybody please suggest a way to show cell text i.e. ‘Y’ in Excel also …?

grd.ExportSettings.ExportOnlyData = true;
  
        grd.ExportSettings.IgnorePaging = true;
  
        grd.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
  
        grd.ExportSettings.OpenInNewWindow = true;


Regards,
Soumya

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Sep 2011, 08:28 AM
Hello Soumya,

I tried the same scenario on my end and it worked as expected. Inorder to change the Cell Text of a given Column  try the following code snippet.
C#:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
 {
   GridDataItem item = e.Cell.Parent as GridDataItem;
   if ((e.FormattedColumn.UniqueName) == "ColUniqueName")
   {
     e.Cell.Text = "Y";
   }
 }

Thanks,
Princy.
0
Winni
Top achievements
Rank 1
answered on 06 Sep 2011, 08:34 AM
Hi
I was able to change the cell text .
When i changed the cell text the problem was in exporting to excel.
i was not able to get the  celll text value(ie Y) in the exported sheet instead i got the bound field value (datetime value).
But export to CSV is exporting the cell text (Y).
I want Excel also export 'Y' .

Regards,
Soumya
Tags
Grid
Asked by
Winni
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Winni
Top achievements
Rank 1
Share this question
or