การสร้าง Report ด้วย Tool ที่ชื่อว่า Microsoft RDLC Report Designer

Mr.Rukpong
2 min readJan 18, 2020

--

เริ่มต้นสร้าง RDLC พื้นฐานด้วย Extension ของ Visual Studio C#

1.ขั้นตอน Install extension ให้เรียบร้อย เริ่มต้นด้วย เลือก Menu Extensions > Manage Extensions ค้นหาคำว่า rdlc แล้วเลือก Install Microsoft RDLC Report Designer

2.Restart โปรแกรม 1 ครั้ง แล้วมาเริ่มสร้าง RDLC กัน เลือก Add > New Item… ค้นหาคำว่า report แล้วกด Add เราจะได้โครง Report มาแล้วครับ

3.มาทดสอบการแสดงผล โดยการ add textbox ไป 1 ตัวด้วยข้อความ test ดังนี้

4.แสดงผล ในที่นี้จะอธิบายการแสดงผล ด้วยวิธี MVC นะครับ (มีส่วน controller, view) ดังนี้

  • ส่วน Contoller จะ using Microsoft.Reporting.WebForms ด้วยครับ เพื่อจะเรียกใช้ ReportViewer เราจะแสดงผล Report RDLC ด้วย Report Viewer ครับ
using Microsoft.Reporting.WebForms;
using System.IO;
using System.Web.Mvc;
namespace TestReport.Controllers
{
public class ReportsController : Controller
{
public ActionResult Index()
{
ReportViewer reportViewer = new ReportViewer
{
ProcessingMode = ProcessingMode.Local, SizeToReportContent = true
};
reportViewer.LocalReport.ReportPath = Path.Combine("C:\\TestReport\\Reports", "Report1.rdlc");
ViewBag.ReportViewer = reportViewer;
return View();
}
}
}
  • ส่วน View จะเรียน @Html.ReportViewer ครับ เพื่อรับข้อมูลของ ReportView ที่โยนมาจาก Controller
@using ReportViewerForMvc
@{
ViewBag.Title = "Example Report";
}
<h2>Example Report</h2>@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)
  • เมื่อเราเตรียม View, Controller เรียบร้อยแล้ว ลองรันดูครับ

ทีนี้เราสามารถเรียง Textbox ต่อกัน เพื่อทำแบบฟอร์ม Report ได้แล้วครับ

บทต่อๆ ไป จะพูดถึง วิธีจัดการกับ Layout ของ RDLC เมื่อมีความซับซ้อนมากขึ้น การเรียง Textbox ธรรมดา อาจจะใช้ไม่ได้แล้ว จะมีวิธีอะไรบ้าง จะพูดในบทความต่อๆ ไป

--

--

Mr.Rukpong
Mr.Rukpong

No responses yet