星期一, 3月 07, 2016

[RV] 顯示外部圖片

實務上有該需求,了解一下要如何做到,下面為顯示外部圖片的簡單紀錄

建立報表

新增報表 ExternalPhoto.rdlc 並進行下列設定,報表資料 => 參數 => 滑鼠右鍵 => 加入參數

[RV] 顯示外部圖片-6

參數名稱:PhotoPath

[RV] 顯示外部圖片-7

設定完後的報表資料視窗

[RV] 顯示外部圖片-3



在報表內插入影像控件,影像屬性內的影像來源設定為外部

[RV] 顯示外部圖片-1

使用此影像運算式,一定要有 "file:///" 字樣在變數前面
= "file:///" & Parameters!PhotoPath.Value

[RV] 顯示外部圖片-2

ReportViewer 控件

拖曳 ReportViewer 控件到 Form 中,並選擇報表

[RV] 顯示外部圖片-4

設定變數來源

利用 Code 把報表中所需的 @PhotoPath 變數丟進報表內
using Microsoft.Reporting.WinForms;

namespace RSPhoto
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 欲連結外部圖片必須設定該屬性
            reportViewer1.LocalReport.EnableExternalImages = true;
            // 設定 Report 內的 @PhoroPath 參數資料
            ReportParameter PhotoPath = new ReportParameter("PhotoPath", @"D:\Demo.jpg");
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { PhotoPath });
            // 更新 ReportViewer
            reportViewer1.RefreshReport();
        }
    }
}
顯示設定結果

[RV] 顯示外部圖片-5

沒有留言:

張貼留言