作成日: 2026/03/25 最終更新日: 2026/05/01
文書種別
使用方法
詳細
アプリケーションの形態を問わず、Printメソッドでレポートを直接印刷できます。
※Webアプリの場合はサーバーサイドのプリンタが出力先になります。
Printメソッドを使用するための具体的な手順は以下の通りです。
-
NuGetパッケージをインストールする
NuGetパッケージマネージャーを使用してプロジェクトに以下のパッケージをインストールします。
MESCIUS.ActiveReports.Viewer.Common.ja
PrintメソッドはMESCIUS.ActiveReports.Viewer.CommonアセンブリのGrapeCity.ActiveReports名前空間に実装されているため、このパッケージが必要になります。
※このパッケージのインストールで警告が表示される場合、後述の制限事項をご確認ください。
-
名前空間をインポートする
印刷を実行するコードファイルの先頭に以下のコードを追加します。
◆サンプルコード (C#)
using GrapeCity.ActiveReports;◆サンプルコード (VB.NET)
Imports GrapeCity.ActiveReports -
SectionDocumentまたはPageDocumentからPrintメソッドを呼び出す
◆サンプルコード (C#)
// ページレポート/RDLレポート var fi = new System.IO.FileInfo("PageReport1.rdlx"); var pageReport = new GrapeCity.ActiveReports.PageReport(fi); var settings = new GrapeCity.ActiveReports.PrinterSettings(); settings.Printer.PrinterName = "プリンタ名"; settings.ShowPrintDialog = false; settings.ShowPrintProgressDialog = false; settings.UsePrintingThread = false; pageReport.Document.Print(settings); // セクションレポート(コード形式) var sectionReport = new SectionReport1(); sectionReport.Document.Printer.PrinterName = "プリンタ名"; sectionReport.Run(); sectionReport.Document.Print(false, false, false); // セクションレポート(XML形式) var xtr = new System.Xml.XmlTextReader("SectionReport1.rpx"); var sectionReport = new GrapeCity.ActiveReports.SectionReport(); sectionReport.LoadLayout(xtr); xtr.Close(); sectionReport.Document.Printer.PrinterName = "プリンタ名"; sectionReport.Run(); sectionReport.Document.Print(false, false, false);◆サンプルコード (VB.NET)
' ページレポート/RDLレポート Dim fi = New System.IO.FileInfo("PageReport1.rdlx") Dim pageReport = New GrapeCity.ActiveReports.PageReport(fi) Dim settings = New GrapeCity.ActiveReports.PrinterSettings() settings.Printer.PrinterName = "プリンタ名" settings.ShowPrintDialog = False settings.ShowPrintProgressDialog = False settings.UsePrintingThread = False pageReport.Document.Print(settings) ' セクションレポート(コード形式) Dim sectionReport = New SectionReport1() sectionReport.Document.Printer.PrinterName = "プリンタ名" sectionReport.Run() sectionReport.Document.Print(False, False, False) ' セクションレポート(XML形式) Dim xtr = New System.Xml.XmlTextReader("SectionReport1.rpx") Dim sectionReport = New GrapeCity.ActiveReports.SectionReport() sectionReport.LoadLayout(xtr) xtr.Close() sectionReport.Document.Printer.PrinterName = "プリンタ名" sectionReport.Run() sectionReport.Document.Print(False, False, False)※上記のコードはファイル(rdlx/rpx)が実行ディレクトリの直下に存在することを前提にしています。
Printメソッドの引数でダイアログの表示有無などを設定できます。
詳細な仕様は以下のリファレンスをご参照ください。
制限事項
MESCIUS.ActiveReports.Viewer.Common.jaはSystem.Drawing.Commonに依存しているため、Windows環境のみがサポートの対象になります。
破壊的変更: System.Drawing.Common が Windows でしかサポートされない - .NET | Microsoft Learn
クロスプラットフォームをターゲットにしているWebアプリやコンソールアプリにインストールすると、以下のように警告マークが表示されます。
弊社としては、警告が表示されるアプリケーション形態での印刷はお勧めしません。
十分な動作確認を実施していないため、予期しない問題が発生する可能性があります。
他のアプリケーション形態や.NET Frameworkへの変更をご検討ください。
どうしても変更が難しい場合は、以下の手順を実施してください。
- プロジェクトのターゲットOSにWindowsを指定する
- 以下のパッケージの最新バージョンをインストールする