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

Radgrid export to multiple excel worksheets

4 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 29 Jan 2013, 03:57 PM
I am exporting data from a radgrid (group by), and I want to put  data into different  worksheets( same workbook) based on group,Can I do that? 

Thanks!

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Feb 2013, 04:22 PM
Hello William,

I'm afraid that this is not possible out-of-the-box. I'm not saying that it is not achievable at all, but a lot of custom code would be involved. Simplified step-by-step instructions below:
- disable the paging in order to show all groups
- traverse the items and build a dictionary of indexes (group;index) pointing to the items belonging the given groups
- use the Export Infrastructure to build the output file by traversing the generated dictionary from the step above

Best regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
William
Top achievements
Rank 1
answered on 04 Feb 2013, 03:40 PM
Thanks, Daniel . I will try it.
0
Sunny
Top achievements
Rank 1
answered on 26 Feb 2013, 03:27 PM
Dear William,

Were you able to achieve the desired functionality? I have the same requirement, grateful if you could share your experience and/or code?

Many thanks,
Sana
0
William
Top achievements
Rank 1
answered on 26 Feb 2013, 03:58 PM
Hi Sana,

Here is what did, hopfully it will help,
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)

{

StringBuilder sb = new StringBuilder();
WorksheetElement workSheet;
foreach () //loop groups pulled from database
{

    workSheet = new WorksheetElement(sectionName); //create new worksheet

    workSheet.Table = CreateTable (groupDetails);

    workSheet.Render(sb);

 

//generate xmlss code
}

e.ExportOutput = e.ExportOutput.Replace("</Styles>", "</Styles>" + sb.ToString()); //add the rendered worksheet to the output
}

private TableElement ParseTable(DataTable aspTable)

{

 TableElement ssTable = new TableElement();

 RowElement ssRow;

 CellElement ssCell;

 ColumnElement ssColumn;

 foreach (DataRow row in aspTable.Rows)

{
    ssRow = new RowElement();

    ssCell = new CellElement();

    ssCell.Data.DataItem = (int)row["fields"];

    ssRow.Cells.Add(ssCell);

    ........

    ssTable.Rows.Add(ssRow);
}

return ssTable;  

}

Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Daniel
Telerik team
William
Top achievements
Rank 1
Sunny
Top achievements
Rank 1
Share this question
or