
I've been messing around with the GridView export functionality and it works great. However, I have a problem when the fields in the excel are "Out of the viewing area".
Excel fields that are not initially within the viewable area are shortened and are impossible to read unless expanded. I found a workaround by adding a column width to every column...but I do not know the size of the columns so they may be cut off. Is there another way to have these fields so that the auto size works in the excel?
13 Answers, 1 is accepted
Can you post more info about how the grid is configured and exported in your scenario?
Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

Here is my Grid
<Grid x:Name="ContentGrid"> |
<telerikGrid:RadGridView x:Name="grdVariance" AutoGenerateColumns="False" IsReadOnly="True"> |
<Navigation:RadContextMenu.ContextMenu> |
<Navigation:RadContextMenu x:Name="radContext" ItemClick="RadContextMenu_ItemClick"> |
</Navigation:RadContextMenu> |
</Navigation:RadContextMenu.ContextMenu> |
<telerikGrid:RadGridView.Columns> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding PartNum}" Header="Part Num" /> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding PONum}" Header="PONum"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding POLine}" Header="POLine"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding PORel}" Header="PORel"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Variance}" Header="PO Variance" DataFormatString="{}{0:c}"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding VendorID}" Header="Vendor ID" /> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding VendorName}" Header="Vendor Name"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipName}" Header="Ship Name"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipAddress1}" Header="Ship Address 1"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipAddress2}" Header="Ship Address 2"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipAddress3}" Header="Ship Address 3"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipCity}" Header="Ship City"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipState}" Header="Ship St"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipZip}" Header="Ship Zip"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipCountry }" Header="Ship Country"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Buyer}" Header="Buyer"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Date}" Header="Order Date" DataFormatString="{}{0:d}" /> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding DueDate}" Header="Due Date" DataFormatString="{}{0:d}" /> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ReceiptDate}" Header="Receipt Date" DataFormatString="{}{0:d}" /> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding HelpDesk}" Header="HD Case" DataFormatString="{}{0:0}" /> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Topic1Desc}" Header="Topic Desc 1"/> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Topic2Desc}" Header="Topic Desc 2"/> |
</telerikGrid:RadGridView.Columns> |
</telerikGrid:RadGridView> |
</Grid> |
Here is my export function
public static void ExportGrid(RadGridView grid) |
{ |
SaveFileDialog dialog = new SaveFileDialog() |
{ |
DefaultExt = "xls", |
Filter = "Excel files (*.xls)|*.xls", |
FilterIndex = 1 |
}; |
try |
{ |
grid.Exporting += new EventHandler<GridViewExportEventArgs>(grid_Exporting); |
if (dialog.ShowDialog() == true) |
{ |
using (Stream stream = dialog.OpenFile()) |
{ |
grid.Export(stream, new Telerik.Windows.Controls.GridViewExportOptions() |
{ |
Format = Telerik.Windows.Controls.ExportFormat.ExcelML, |
ShowColumnHeaders = true |
}); |
} |
} |
} |
catch (IOException) |
{ |
MessageBox.Show("File with the current name is open. Please rename or close the open file", "Error", MessageBoxButton.OK); |
} |
} |
Here is the Export trigger
static void grid_Exporting(object sender, GridViewExportEventArgs e) |
{ |
if (e.Element == ExportElement.HeaderRow || e.Element == ExportElement.FooterRow |
|| e.Element == ExportElement.GroupFooterRow) |
{ |
e.Height = 25; |
e.FontSize = 20; |
e.FontWeight = FontWeights.Bold; |
} |
else if (e.Element == ExportElement.Row) |
{ |
e.Height = 15; |
} |
else if (e.Element == ExportElement.GroupHeaderRow) |
{ |
e.FontFamily = new FontFamily("Verdana"); |
e.Background = Colors.LightGray; |
e.Height = 30; |
} |
(sender as RadGridView).Exporting -= grid_Exporting; |
} |
I've tried this however didn't get such problem. You can check the attached example application for reference.
Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

private
void btnExport_Click(object sender, RoutedEventArgs e)
{
try
{
string extension = "xls";
SaveFileDialog dialog = new SaveFileDialog()
{
DefaultExt = extension,
Filter =
String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
FilterIndex = 1
};
if (dialog.ShowDialog() == true)
{
using (Stream stream = dialog.OpenFile())
{
using (StreamWriter sw = new StreamWriter(stream, Encoding.UTF8))
{
sw.Write(radGridView.ToHtml());
}
stream.Close();
}
}
}
catch (IOException)
{
MessageBox.Show("File with the current name is open. Please rename or close the open file", "Error", MessageBoxButton.OK);
}
}
static void RadGridView1_Exporting(object sender, GridViewExportEventArgs e)
{
if (e.Element == ExportElement.HeaderRow )
{
e.Height = 25;
e.FontSize = 20;
e.FontWeight =
FontWeights.Bold;
}
else if (e.Element == ExportElement.Row)
{
e.Height = 15;
}
else if (e.Element == ExportElement.GroupHeaderRow)
{
e.FontFamily =
new FontFamily("Verdana");
e.Background =
Colors.LightGray;
e.Height = 30;
}
//(sender as RadGridView).Exporting -= grid_Exporting;
}
Can you send us small running example application where this can be reproduced?
Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

I am trying to calculate the amount total footer in excel sheet this is not required to display on grid. Can you please send any example.
I am getting this error for DEMO CODE
Error 22 'Telerik.Windows.Controls.ExportElement' does not contain a definition for 'GroupFooterCell'
else if (e.Element == ExportElement.GroupFooterCell)
{
GridViewDataColumn column = e.Context as GridViewDataColumn;
AggregateFunctionsGroup group = e.Value as AggregateFunctionsGroup;
if (column != null && group != null && column.AggregateFunctions.Count() > 0)
{
AggregateResultCollection aggregateResults = group.GetAggregateResults(column.AggregateFunctions);
List<string> result = new List<string>();
foreach (AggregateResult r in aggregateResults)
{
if (r.FormattedValue != null)
{
result.Add(r.FormattedValue.ToString());
}
}
e.Value = String.Join(",", result.ToArray());
}
}

The GridViewExportOptions object has an Items property. Simply set it to your RadDataPager's ItemsSource property and perform the export operation.
Sincerely yours,Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

Dear Yavor Georgiev ,
Thanks for reply
i didn't find RadDataPager's ItemsSource property for Radgrid...
But i used the following code for exporting Radgrid to Excel when button click
protected
void Button1_Click(object sender, EventArgs e)
{
RadGrid1.MasterTableView.ExportToExcel();
}
I am able to get exporting but not ignoring the paging.
Please help to get all the records.. try to send complete code to export Radgrid to Excel
Regards,
Prathap Narravula
This code is related to our RadGrid for ASP.NET/ASP.NET AJAX. Please post your questions in the relevant forum!
Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

Please send me the code in Ajax.. I am also using ajax

As I understand from your post the columns outside the viewing area are squeezed, not hidden. Is that correct?
I was able to reproduce that they are hidden, but not that they are squeezed when I am using the Export method of the RadGridView. May you please share with what example have you used to do the export? Are you doing the exporting with the Export method or with RadDocument?
Didie
the Telerik team