ReportViewer产PDF报表其实真的很好用~但新的版本好像没办法装完SSDT就可以使用…
【开发工具】
Visual Studio 2022
【使用套件】
ReportViewerForMvc14 >>Nuget连结<<
【使用模组】
Microsoft RDLC Report Designer 2022 >>Marketplace连结<<
【步骤】
1. 开启专案后发现没有可以新增报表(.rdlc)的选项。
2. 安装Microsoft RDLC Report Designer 2022。
3. 安装完成后可以在延伸模组管理员内看到Rdlc报表设计工具(如下图)。
4. 此时新增项目就可以找到「报表」,这个就是我们熟悉的rdlc了。
5. 安装Report Viewer套件。
6. 资料设定可以参考先前的文章『[ASP.NET] MVC使用rdlc报表』。
【补充】
由于我们产表常常会是后端产完就好,另外再进行运用,因此记录一下产档程式码如下。
Microsoft.Reporting.WebForms.ReportViewer reportViewer = new Microsoft.Reporting.WebForms.ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.ReportPath = $"RDLC档案的实体路径";
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("RDLC内资料来源的名称", data));
string mimeType, encoding, fileNameExtension;
string[] streams;
Warning[] warnings;
byte[] pdfBytes = reportViewer.LocalReport.Render(
"PDF", // 指定输出格式
null, // 预设装置资讯
out mimeType, out encoding, out fileNameExtension,
out streams, out warnings
);
File.WriteAllBytes("档案要储存的实际位置",pdfBytes);