C# Report

如何製作報表

1.     使用NuGet - Solution下載Microsoft.ReportingServices.ReportViewerControl.Winforms

2.     使用Manage Extensions中下載Microsoft RDLC Report Designer 2022




步驟

1.     LocalReport物件建立出來

                        LocalReport localReport = new LocalReport();

2.     設定Report樣板路徑

檔案的副檔名是使用rdlc,可以使用Report Designer進行編輯

localReport.ReportPath = 路徑;

localReport.ReportPath = "C:\Test.rdlc";

 

3.     設定報表數據

data 的類型IEnumerable

localReport.DataSources.Add(new ReportDataSource(資料集名稱, data));

4.     生成報表

提供byte[] 類型

localReport.Render(輸出檔案的副檔名);

localReport.Render("pdf");

                        寫成檔案

File.WriteAllBytes("檔案名",byte[] 變數);

File.WriteAllBytes("Test.pdf", localReport.Render("pdf"));

Comments

Popular posts from this blog

Git 環境設定

資料結構 - 佇列 (Data Structure - Queue)