Reputation: 1389
We need to generate a RDLC report directly as Word or PDF without using Report Viewer. Here we have two issues.
1) When rendering the report as docx using the format as "WORDOPENXML". MS Word (2013) cant open the generated file. It gives following error,
we're sorry we can't open docx because we found problem with its contents file is corrupt and cannot be opened.
However it can be generated as a doc using the format as "WORD". Then it can be opened successfully.
But I prefer generate it as Docx if at all posible.
2) Even though we can generate it as doc file, background images in the header section are missing. We have use the Letterhead as the background image of the report.
There are no issues when generating the report as PDF.
Here is the code used to generate the report.
ReportViewer reportViewer = new ReportViewer();
LocalReport localReport = new LocalReport();
localReport.ReportPath = Path.Combine(_env.ReportPath, "RollReport.rdlc");
//Set the datasource for the report
localReport.DataSources.Clear();
localReport.DataSources.Add(new ReportDataSource("Details", dtBCDetails));
localReport.DataSources.Add(new ReportDataSource("Properties", dtPropDetails));
localReport.DataSources.Add(new ReportDataSource("Insurence", dtInsurence));
localReport.DataSources.Add(new ReportDataSource("PropertyOwners", dtPropertyOwners));
//Pass parameters to the report
localReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter("BodyCorporateID", bcid.ToString()) });
localReport.Refresh();
//Get the byte stream for the report rendered as PDF
byte[] bytes = localReport.Render(format, null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
Stream repStream = new MemoryStream(bytes);
Any help would be greatly appreciated. Thank you, Wijitha
Upvotes: 2
Views: 3667
Reputation: 564
Don't know, if you still need the information, but I can help you at least with the docx... If you use WORDOPENXML instead of WORD as format parameter, a docx file is generated.
Upvotes: 4