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

How to remove white space after string in export excel file

2 Answers 499 Views
Grid
This is a migrated thread and some comments may be shown as answers.
york
Top achievements
Rank 1
york asked on 04 Jul 2011, 06:16 AM
Hi,
I want to remove white space after string in each cell in exported excel file from radgrid, see attached image. How to do it? Thanks.
Also the datetime field does not contain AM or PM. But in radgrid, they contain AM/PM. What is the problem?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Jul 2011, 07:32 AM
Hello York,

I suppose you have set "AllowFilteringByColumn" as "true". Try the following code snippet to hide this when exporting to excel.

C#:
protected void button1_Click(object sender, EventArgs e)
  {
      RadGrid1.ExportSettings.ExportOnlyData = true;    
      RadGrid1.MasterTableView.AllowFilteringByColumn = false;

      RadGrid1.MasterTableView.ExportToExcel();
  }


For second scenario, try setting DataFormatString in aspx to restore datetime field when exporting to excel. Hope this helps.

aspx:
<telerik:GridBoundColumn UniqueName="BirthDate"  HeaderText="BirthDate" DataType="System.DateTime"
DataField="BirthDate" DataFormatString="{0:dd/mm/yyyy hh:mm tt}">
</telerik:GridBoundColumn>

Thanks,
Shinu.
0
york
Top achievements
Rank 1
answered on 04 Jul 2011, 08:12 AM
Hi Shinu,

The white spaces are not removed after adding RadGrid1.MasterTableView.AllowFilteringByColumn = false;

The second one is working except DataFormatString="{0:dd/MM/yyyy hh:mmtt}.
It is a bit weird because it is case-sensitive first, and hh:mm tt is not working for excel file (work for radgrid1 display however), but hh:mmtt is working,  however leave no space between second and AM/PM. Any thought? 

Thanks.
York
Tags
Grid
Asked by
york
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
york
Top achievements
Rank 1
Share this question
or