This project has moved. For the latest updates, please go here.

AppendReport Seems To Not Work?

Dec 15, 2011 at 3:53 PM

 Hello,

I have two sets of data and seperately they work fine.  However, I want to merge there data together.  The data schema is not the same but I just assume that Appending the second report to the first would just give me another Worksheet in the Excel Workbook?

I have tried appending 1 to 2 and 2 to 1 but neither result in any data excel the one on the last line of the code below.

Report report = new Report(Result.RawData.ToReportSource());
Report report2 = new Report(Result.Rollup.ToReportSource());
report.TextFields.Title =
"Cardiac Surgery Pending Surgeries Report";

report2.TextFields.Title =
"Rollup Data";

DoddleReport.OpenXml.ExcelReportWriter writer = new DoddleReport.OpenXml.ExcelReportWriter();
writer.AppendReport(report, report2);
writer.WriteReport(report, Context.Response.OutputStream);

Is there something I am doing wrong?  Or perhaps does this not work in the OpenExcel writer?

Thanks,
Kevin

Coordinator
Dec 15, 2011 at 3:55 PM

Unfortunately the only ReportWriter that currently supports AppendReport is the ABCPDF Report writer.

Developer
Dec 21, 2011 at 9:37 PM

Hey Kevin,

I added the functionnality to the writer in the net40-spike branch. You can get the code directly or wait until Matt build the new NuGet package. Let me know if it works out for you. The only thing I noticed that you will need to change from your code, is that you need to pass an ExcelReportWriter instance to the reports you create. Then you can call WriteReport on the report directly and it'll merge eveyrthing in the same excel file, under different sheets as expected.

Louis

Dec 22, 2011 at 1:05 AM
Awesome-tastic. Thank you very much.

Sent from my Windows Phone

From: lpperras
Sent: 12/21/2011 5:37 PM
To: kevingrigsby@hotmail.com
Subject: Re: AppendReport Seems To Not Work? [doddlereport:283107]

From: lpperras

Hey Kevin,

I added the functionnality to the writer in the net40-spike branch. You can get the code directly or wait until Matt build the new NuGet package. Let me know if it works out for you. The only thing I noticed that you will need to change from your code, is that you need to pass an ExcelReportWriter instance to the reports you create. Then you can call WriteReport on the report directly and it'll merge eveyrthing in the same excel file, under different sheets as expected.

Louis

Jan 20, 2012 at 6:16 PM

I'm trying to use the append feature also.  I pulled the code from the net40-spike branch, but still can't get it to work.  Including changes based on Louis comments, would this be the correct way to write it?  For me, I'm only getting a file with one tab containing the first report.

DoddleReport.OpenXml.ExcelReportWriter writer = new DoddleReport.OpenXml.ExcelReportWriter(); 

Report report = new Report(Result.RawData.ToReportSource(), writer);
Report report2 = new Report(Result.Rollup.ToReportSource(), writer); 
report.TextFields.Title ="Cardiac Surgery Pending Surgeries Report"; 
report2.TextFields.Title ="Rollup Data"; 

writer.AppendReport(report, report2);
report.WriteReport(Context.Response.OutputStream);

Nov 7, 2012 at 2:57 PM

I am having difficulty as well, the AppendReport feature would be very useful but I am unsure about the proper method to get it to work. I can't really find any documentation nor is it clear from the sample project.

Below is my code sample - it is for excel but i would add an extension switch for each output format (pdf, html etc.)

Report parent = new Report(Result.ToReportSource());

Report child = new Report(Result2.ToReportSource());

//report customizations

parent.Writer = new doddleReport.OpenXml.ExcelReportWriter();
parentReport.AppendReport(child);

return new ReportResult(parent,parent.Writer);                                    

 

The above is oddly returning a zip package and is not working.  Any suggestions on the proper implementation would be appreciated.

 

thanks

John

Nov 8, 2012 at 2:51 PM

After some investigation with an asp.net MVC 4 project, one correct method is the following:

            var query = DoddleProductRepository.GetAll().Take(1);
            var childquery = DoddleProductRepository.GetAll().Take(1);


            DoddleReport.OpenXml.ExcelReportWriter writer = new DoddleReport.OpenXml.ExcelReportWriter();
            
            var parent = new Report(query.ToReportSource(), writer);
            var child = new Report(childquery.ToReportSource(), writer);
            parent.AppendReport(child);

            return new ReportResult(parent, writer) { FileName = "test.xlsx" };

During my testing I kept getting a zip file pushed out but only when I was using a controller action with parameters.  Simply using the filename override above resolved the issue.  I'm not sure what's causing the issue (GetDownloadFileExtension?) but it does work as above.

 

Apr 3, 2013 at 3:33 PM
jshannon99 wrote:
After some investigation with an asp.net MVC 4 project, one correct method is the following: var query = DoddleProductRepository.GetAll().Take(1); var childquery = DoddleProductRepository.GetAll().Take(1); DoddleReport.OpenXml.ExcelReportWriter writer = new DoddleReport.OpenXml.ExcelReportWriter(); var parent = new Report(query.ToReportSource(), writer); var child = new Report(childquery.ToReportSource(), writer); parent.AppendReport(child); return new ReportResult(parent, writer) { FileName = "test.xlsx" }; During my testing I kept getting a zip file pushed out but only when I was using a controller action with parameters.  Simply using the filename override above resolved the issue.  I'm not sure what's causing the issue (GetDownloadFileExtension?) but it does work as above.  
AppendReport is working for me, however I am wondering if there is a way to name the tabs on the excel spreadsheet?
May 8, 2013 at 12:09 PM
Edited May 8, 2013 at 12:10 PM
NoTalenAtAll wrote:
AppendReport is working for me, however I am wondering if there is a way to name the tabs on the excel spreadsheet?
For OpenXml.ExcelReportWriter you just need to specify SheetName render hint.
report.RenderHints["SheetName"] = "MySheetName";
Oct 16, 2013 at 2:36 PM
I've created a modified version of the iTextSharp PdfReportWriter for my own needs that supports AppendReport. I've extracted out the logic that adds a report to the PDF document to a new method named AddReportToDocument and used method Document.NewPage to ensure that every report starts on a new page.

I've created a gist at https://gist.github.com/pieterbeens/7008672.
May 8, 2014 at 2:07 PM
Thank you pietbeenz, I used your AppendablePdfWriter and am able to append report in PDF. Thanks.