文章分類/

Infragistics|Ultimate UI for WPF|使用 Infragistics.Reports 打印 XamDataGrid

尚無瀏覽量
2023-09-03 更新

infragistics log

介紹

Infragistics.Reports 是一個功能強大的代碼庫,包含在 WPF 產品的 Ultimate UI 中。它的創建是為了讓開發人員能夠在其應用程序中輕鬆提供 XamDataGrid 打印和導出到 XPS。它還提供通過添加頁眉或頁腳、添加自定義圖像等來自定義文檔的功能。您可以在打印機上打印整個窗口以及視覺元素。可以打印任何元素,包括圖表和圖像。庫中添加了打印預覽控件等輔助控件,以改善文檔打印/導出體驗。本文將向您展示如何打印 XamDataGrid 並將報表與打印機關聯。

基礎設施.報告設置

添加對 InfragisticsWPF4.Reporting 程序集的引用。該程序集包含寫入打印機或 XPS 文檔的方法。接下來,創建 Report 類的一個實例。該元素是要打印的元素。報告是在部分集合中創建的。每個部分都包含內容。Infragistics.Windows.Reports.EmbeddedVisualReportSection 是一個有用的關鍵類。可應用於部分的視覺元素。

Infragistics.Windows.Reporting.Report myReport = new Infragistics.Windows.Reporting.Report();
Infragistics.Windows.Reporting.EmbeddedVisualReportSection myXamDataGridReport = new Infragistics.Windows.Reporting.EmbeddedVisualReportSection(this.xamDataGrid1);
myReport.Sections.Add(myXamDataGridReport);

打印預覽

接下來,將要打印的文檔發送到打印預覽對話框。使用 Infragistics XamReportPreview 控件。將該控件添加到您的 WPF 應用程序中,如下所示。

XAML 端

<Window x:Class="XamCommunitySample.MainWindow1"
    xmlns:igReports="http://infragistics.com/Reporting" ...>
    <igReports:XamReportPreview x:Name="xamReportPreview1" />
</Window>

C#端

//Method Signature GeneratePreview(Report, bool showPrintDialog, bool showReportProgressControl);
xamReportPreview1.GeneratePreview(myReport, false, true);

使用XamReportPreview控件的GeneratePreview方法並傳遞創建的Report。該方法定義具有改善打印體驗的參數。參數為:

  • Infragistics.Windows.Reports.Report – 要打印或預覽的報告。
  • bool ShowPrintDialog – 顯示設置打印機和打印位置的標準 PrintPreviewDialog。
  • bool ShowReportProgressControl – 顯示一個幫助對話框,顯示創建打印預覽時的進度。

印刷

最後,有兩種對於打印文檔很重要的方法。導出並打印。這些方法將文檔導出到 XPS 並將文檔發送到打印機。下面是代碼。

myReport.Print();
myReport.Export(Infragistics.Windows.Reporting.OutputFormat.XPS, "FileLocation");

這就是所有必要的步驟。只需幾行代碼,您就可以打印/導出 XamDataGrid 和其他可視元素。

快速跳轉目錄

✦ 群昱 AccessSoft 你的全面軟體解決方案 ✦

身為全球眾多知名軟體在台灣合作夥伴,歡迎諮詢你需要的軟體服務!

Picture of 軟體專家
軟體專家

群昱作為全球知名軟體推薦合作夥伴,致力於提供更多軟體解決方案給你!

更多軟體新知

立即詢價

請留下完整資訊,以便我們提供精確的服務內容給你。

詢價資訊