I am using SelfHierarchy within my RadGrid and would like to use ExportToExcel and ExportToWord functionality. But when I export to excel or word, I see command buttons and other data are exported as-well. For example I use below code to export rows collapsed.
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName.Contains(
"Export"
))
{
RadGrid theGrid = (RadGrid)source;
theGrid.MasterTableView.HierarchyDefaultExpanded =
false
;
}
}
5 Answers, 1 is accepted
Export of self-referencing RadGrid is not supported out-of-the-box and this is why it might behave unexpectedly in some cases. Nevertheless I prepared a simple demo showing how to remove the unwanted controls.
We strongly recommend that you use RadTreeList control instead of RadGrid with self-referencing hierarchy.
Regards,
Daniel
the Telerik team
i am exporting heirarchy radgrid in excel
how to export radgrid in excel without OnNeedDataSource
i am binding datasource to radgrid on button click event
if i am not use OnNeedDataSource,it give me object reference is null
my code for binding grid is
grd_firstchart_aco.DataSource = table;
grd_firstchart_aco.DataBind();
and code for export to excel is below
grd_forth_aco.ExportSettings.ExportOnlyData = true;
grd_forth_aco.ExportSettings.IgnorePaging = true;
grd_forth_aco.ExportSettings.OpenInNewWindow = true;
grd_forth_aco.ExportSettings.FileName = "fileName";
grd_forth_aco.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
grd_forth_aco.ExportSettings.HideStructureColumns = true;
grd_forth_aco.MasterTableView.HierarchyDefaultExpanded = true;
grd_forth_aco.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;
grd_forth_aco.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
grd_forth_aco.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;
grd_forth_aco.MasterTableView.ExportToExcel();
thanks
Hello Asutosh,
I see you have opened several threads with the very same content. I advise that you post only one per issue because this will let the person examining a case focus their efforts in one place instead of spreading information across different channels. I am closing this one, this one and this one and I suggest you continue the discussion here or open a new support ticket from your account in case your issue is urgent.
Regards,
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.
I am using this telerik control in my WPF application . I have one button and on click of that button i am exporting RadGridview data to excel. here is my code
private void btnExportexecl_Click(object sender, RoutedEventArgs e)
{
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)
{
Stream stream = dialog.OpenFile();
datagrid2.ExportAsync(stream,
new GridViewExportOptions()
{
Format = ExportFormat.ExcelML,
ShowColumnHeaders = true,
ShowColumnFooters = true,
ShowGroupFooters = false,
Encoding=Encoding.Unicode
}, true);
}
}
but this is exporting only one page .i have also used pagination in that case it exports the current page..i want to export all the 50 pages i tried all the above but Still struggling.. any help will be appreciated. thank you
When the WPF RadGridView is paged, only the current page is exported. There are a couple of approaches that you can use to avoid that:
1. Use the approach explained here and demonstrated in the ExportPagedDataExcel demo. It includes preserving the page index and size, setting them to 0 in order to export the data and then back to their values.
2. Set the Items property of the export options to your bound collection during the time of the export
datagrid2.ExportAsync(stream,
new GridViewExportOptions()
{
Format = ExportFormat.ExcelML,
ShowColumnHeaders = true,
ShowColumnFooters = true,
ShowGroupFooters = false,
Encoding=Encoding.Unicode,
Items=YourBoundCollection
}, true);
I hope this is helpful. If you have additional questions about RadGridView for WPF please post them in the designated forum section.
Regards,
Petya
Telerik