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

Export Multiple Reports in a single excel worksheet

6 Answers 133 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jhon Jairo Zapata Montealegre
Top achievements
Rank 1
Jhon Jairo Zapata Montealegre asked on 06 May 2010, 04:53 PM
Hi, I have a reportviewer with a couple of reports but I need to export them in a single worksheet, is that posible, or what's the right approach. Thanks

6 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 10 May 2010, 03:31 PM
Hi Jhon Jairo Zapata Montealegre,

I suppose you are using a ReportBook. By design when the ReportBook is exported to excel a separate sheet is created for every report. Our suggestion would be to set up a report with SubReports in code behind and export the newly created report as shown in the following code snippet:

protected void  Button1_Click(object sender, EventArgs e)
{
            var report = new Telerik.Reporting.Report();
             
            var subReport1 = new Telerik.Reporting.SubReport();
            subReport1.Width = Telerik.Reporting.Drawing.Unit.Inch(0.1);
            subReport1.Height = Telerik.Reporting.Drawing.Unit.Inch(0.1);
            subReport1.ReportSource = new Telerik.Reporting.Examples.CSharp.BarcodesReport();
            var subReport2 = new Telerik.Reporting.SubReport();
            subReport2.ReportSource = new Telerik.Reporting.Examples.CSharp.DashBoard();
            subReport2.Top = Telerik.Reporting.Drawing.Unit.Inch(0.4);
            subReport2.Width = Telerik.Reporting.Drawing.Unit.Inch(0.1);
            subReport2.Height = Telerik.Reporting.Drawing.Unit.Inch(0.1);
            var detailSection = new Telerik.Reporting.DetailSection();
            detailSection.Items.Add(subReport1);
            detailSection.Items.Add(subReport2);
            report.Items.Add(detailSection);
             
            var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
            Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("XLS", report, null);
            var fs = new System.IO.FileStream ("c\\report1.xls", System.IO.FileMode.Create);
            fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            fs.Flush();
            fs.Close();
                 
}

Regards,
Peter
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.
0
Manar
Top achievements
Rank 1
answered on 31 Jan 2013, 12:26 AM
Hello Peter,

I tried your code and I got the 2 report in the same worksheet, do you have any idea how I can put each one of them in separate worksheet in the same excel file?


Thanks,
Manar
0
Peter
Telerik team
answered on 01 Feb 2013, 11:54 AM
Hi Manar,

Have you tried to combine the reports with a ReportBook? Generally when a ReportBook is exported to excel a separate sheet is created for every report. 

All the best,
Peter
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Manar
Top achievements
Rank 1
answered on 01 Feb 2013, 03:18 PM
I got it, thanks a lot
0
Joseph
Top achievements
Rank 1
answered on 19 Mar 2021, 12:29 AM

what about if we want to also include the headers and footers in this situation? or is there a way to use the report book to combine multiple reports into a single excel file but have them all show up on a single sheet?

Thanks.

0
Mads
Telerik team
answered on 23 Mar 2021, 12:56 PM

Hi Joeseph,

As stated in the documentation for Excel Rendering Design Considerations:

Each report in a ReportBook will occupy a separate worksheet in the Excel workbook. Each worksheet of the Excel workbook will have the name of the respective report.

If you want multiple reports to show on a single sheet, I recommend using SubReport items.

Page-headers and -footers will no longer be available, but group-headers and -footers can be used instead in a similar way. Add a new static group to the report, meaning a group with an empty expression, which will keep the data within one collection, but make group-headers and -footer available. Each of these sections has a property called 'PrintOnEveryPage' which can be set to 'true'. When this is done, they will act very similarly to page-headers and -footers.

I hope you find this information useful. Let me know if you have any further questions.

Regards, Mads Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Jhon Jairo Zapata Montealegre
Top achievements
Rank 1
Answers by
Peter
Telerik team
Manar
Top achievements
Rank 1
Joseph
Top achievements
Rank 1
Mads
Telerik team
Share this question
or