6 Answers, 1 is accepted
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();
}
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.
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
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!
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.
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/.