on 06-06-2015 1:00 AM
プレビュー表示後に印刷アイコンをクリックし、プリンタ選択することでレポートに保存されているプリンタ情報が初期化されてしまいます。回避策の一つとしては、使用プリンタ、用紙サイズ、印刷方向をデフォルトで設定してご利用いただくことになります。
また、印刷アイコンではなく、PrintToPrinter 関数を利用することも回避策になると思います。
Yoshi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
以下のリンクのページに掲載されたサンプルコード (C#) のように記述します。
http://scn.sap.com/docs/DOC-28851
(記述例)
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("ReportName"));
System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = "PinterName";
System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings);
rpt.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;
rpt.PrintOptions.PrinterDuplex = PrinterDuplex.Simplex;
rpt.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);
プリンタへの印刷前に設定される項目としては、以下のものが考えられます。
プリンタ名 : printerSettings.PrinterName
部数 : printerSettings.Copies
用紙サイズ: pSettings.PaperSize
印刷方向 : pSettings.Landscape
スケール : PrintLayout.Scaling
Yoshi
以下のリンクのページの VB.NET (VB) Windows Sample Applications for use in Microsoft Visual .Net 2002 and Later(net_win_smpl.exe) に VB のサンプルアプリケーションがございますのでご参照ください。
http://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports+for+.NET+SDK+Samples
Yoshi
以下のリンクのページから「VB.NET (VB) Windows Sample Applications for use in Microsoft Visual .Net 2002 and Later.」をクリックして、net_win_smpl.exe をダウンロードします。
http://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports+for+.NET+SDK+Samples
以下のフォルダに解凍後、vbnet_win_printtoprinter.zip ファイルを解凍します。
C:\Crystal\CRNET
Microsoft Visual Stuido 2010(2012 が準備できていないため) でプロジェクトファイル (PrintToPrinter.sln) を開きます。
変換後、コード修正なしで、そのまま実行してプリンタへ印刷されることを確認しました。
このサンプルコードでは、コマンドボタンに以下の記述がございます。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
''Create an instance of the Income Statement report.
crReportDocument = New Income_Statement()
''Use error handling in case an error occurs
Try
''Set the printer name to print the report to. By default the sample
''report does not have a defult printer specified. This will tell the
''engine to use the specified printer to print the report. Print out
''a test page (from Printer properties) to get the correct value.
crReportDocument.PrintOptions.PrinterName = "\\server\myprinter"
''Start the printing process. Provide details of the print job
''using the arguments.
crReportDocument.PrintToPrinter(1, True, 1, 1)
''Let the user know that the print job is completed.
MessageBox.Show("Report finished printing!")
Catch err As Exception
MessageBox.Show(err.ToString())
End Try
End Sub
ご提示いだいたエラーですが、動作環境 (Windows)、Crystal Reports ランタイム、実行ファイルのそれぞれの 32 ビット、64 ビットに不一致が存在しないでしょうか?
ちなみ以下の環境でサンプルコードが動作しました。
- Windows 7 64bit
- VS 2010 コンパイルプラットフォーム AnyCPU
- SAP Crystal Reports runtime engine for .NET Framework (64-bit) 13.0.14.1720
- SAP Crystal reports, version for Microsoft Visual Studio 13.0.14.1720
Yoshi
以下のような記述を利用することになります。
(記述例)
crReportDocument = New ReportDocument
'レポート読み込み
crReportDocument.Load("C:\Income Statement.rpt")
'プリンタ名
crReportDocument.PrintOptions.PrinterName = "\\server\myprinter"
'用紙サイズ
crReportDocument.PrintOptions.PaperSize = PaperOrientation.Portrait
'印刷方向
crReportDocument.PrintOptions.PaperOrientation = PaperSource.Auto
'給紙方法
crReportDocument.PrintOptions.PaperSource = PaperSize.DefaultPaperSize
Yoshi
以下のリンクのページサンプルコード (SAP Crystal Reports NET SDK Tutorial Sample Code.NET SDK Tutorial Sample Code.zip) がございますのでご参照ください。
http://scn.sap.com/docs/DOC-6948
この zip ファイルの以下のフォルダにデータベース接続するための記述例がございます。
Tutorial_Sample_Code\ViewerObjectModel\DBLogon\VB\VB_Win_CRVObjMod_DBLogon
これを参考にして以下のような記述で Oracle データベースに接続することができると思います。
(記述例)
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Dim crTableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
With crConnectionInfo
.ServerName = "<サービス名>"
.UserID = "<ユーザ名>"
.Password = "<パスワード>"
End With
For i As Integer = 0 To crReportDocument.Database.Tables.Count - 1
crTableLogoninfo = crReportDocument.Database.Tables(i).LogOnInfo
crTableLogoninfo.ConnectionInfo = crConnectionInfo
crReportDocument.Database.Tables(i).ApplyLogOnInfo(crTableLogoninfo)
Next
Yoshi
Yoshi Takaseさんご回答ありがとうございます。 ご指示いただいたサンプルファイルおよび参考コードを参考に以下のように記述しましたが 印刷しても rptファイル作成した時の状態で印刷され、データを更新したものが印刷 されませんでした。 どの部分が間違っているのでしょうか? Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Public Class Form1 Inherits System.Windows.Forms.Form ''CR Variables Dim crReportDocument As ReportDocument #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Friend WithEvents Button1 As System.Windows.Forms.Button 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'Button1 ' Me.Button1.Font = New System.Drawing.Font("Microsoft Sans Serif", 16.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Button1.Location = New System.Drawing.Point(72, 64) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(144, 128) Me.Button1.TabIndex = 0 Me.Button1.Text = "Print Report" ' 'Form1 ' Me.AcceptButton = Me.Button1 Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1}) Me.Name = "Form1" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Print to Printer" Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ''Create an instance of the Income Statement report. 'crReportDocument = New Income_Statement() 'データベース更新(Start) 'Imports CrystalDecisions.CrystalReports.Engine 'Imports CrystalDecisions.Shared Dim crTableLogoninfo As New TableLogOnInfo() Dim crConnectionInfo As New ConnectionInfo() crReportDocument = New ReportDocument crReportDocument.Load("Z:\送り状.rpt") With crConnectionInfo .ServerName = "orcl" .UserID = "USER" .Password = "password1" End With For i As Integer = 0 To crReportDocument.Database.Tables.Count - 1 crTableLogoninfo = crReportDocument.Database.Tables(i).LogOnInfo crTableLogoninfo.ConnectionInfo = crConnectionInfo crReportDocument.Database.Tables(i).ApplyLogOnInfo(crTableLogoninfo) Next 'データベース更新(End) crReportDocument.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4 'crReportDocument.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation 'crReportDocument.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape '用紙の向きが横 crReportDocument.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait '用紙の向きが縦 crReportDocument.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Auto '給紙方法は自動 ''Use error handling in case an error occurs Try ''Set the printer name to print the report to. By default the sample ''report does not have a defult printer specified. This will tell the ''engine to use the specified printer to print the report. Print out ''a test page (from Printer properties) to get the correct value. 'crReportDocument.PrintOptions.PrinterName = "\\server\myprinter" crReportDocument.PrintOptions.PrinterName = "\\FUKUIDBS.FUKUIPDC.FNS.LOCAL\NetPR_24" 'crReportDocument.PrintOptions.PaperSize = "A4" ''Start the printing process. Provide details of the print job ''using the arguments. crReportDocument.PrintToPrinter(1, True, 1, 1) ''Let the user know that the print job is completed. MessageBox.Show("Report finished printing!") Catch err As Exception MessageBox.Show(err.ToString()) End Try End Sub End Class 以上、よろしくお願いいたします。
Yamamoto様
お手数掛け致しますが、この追加のご質問について、
一つ新規スレッドの作成をご協力頂けますでしょうか。
現在のようなスレッド一つだけで複数のご質問は、スレッド自体も長くなり読み辛くなります。
一方、新規スレッドの作成より、読みやすくなり、Yoshiさん以外他の方から回答いただくこともあります。
また、もしこの前発生した現象は既に解決された場合、どの返信内容が役に立つかを今後確認できるため、お手数ですが、この前に返信内容下にある「Correct Answer」、「Helpful Answer」をクリックし、設定をお願いいたします。
以上、ご協力よろしくお願いいたします。
Xiaoping
レポートのデザイン時のページ設定やコードから印刷されるときのプリンタ関連の設定などを詳細にお知らせください。
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
レポート表示後、プリンタ選択時に用紙サイズ、印刷方向を選択して印刷していると解釈して間違いございませんか?
また、用紙サイズ 200x80 は、横長の幅 200 で高さ 80 と解釈して間違いございませんか?
例えば、動作環境でレポート表示後、印刷アイコンをクリックしたときにデフォルトで表示されるように通常使うプリンタにレポートをデザインしたときのプリンタを設定し、用紙サイズ、印刷方向などもデフォルトで設定してお試しください。
印刷アイコンではなく、コード上で PrintToPrinter 関数を利用して本事象が解消できるかお試しください。
以下のリンクに PrintToPrinter 関数に関連する記事がございます。
http://scn.sap.com/docs/DOC-28851
また、以下のリンクの SCN サイトから類似の事例を検索してみてください。
http://scn.sap.com/community/crystal-reports-for-visual-studio
Yoshi
Yoshi Takaseさん、大変お世話になりありがとうございます。
>レポート表示後、プリンタ選択時に用紙サイズ、印刷方向を選択して印刷していると解釈して間違いござい>ませんか?
はい。用紙サイズ、印刷方向は選択しています。
>また、用紙サイズ 200x80 は、横長の幅 200 で高さ 80 と解釈して間違いございませんか?
はい。
>例えば、動作環境でレポート表示後、印刷アイコンをクリックしたときにデフォルトで表示されるように通常使>うプリンタにレポートをデザインしたときのプリンタを設定し、用紙サイズ、印刷方向などもデフォルトで設定し>てお試しください。
使用プリンタ、用紙サイズ、印刷方向をデフォルトにすると正常に印刷されます。
>印刷アイコンではなく、コード上で PrintToPrinter 関数を利用して本事象が解消できるかお試しください。
試してみます。
Yoshi Takaseさん、お返事遅れまして申し訳ありません。
PrintToPrinterで検索して、英語ばかりで面食らいましたが、
翻訳しながら頑張ってみましたが、どうもわかりませんでした。
PrintToPrinterを使用して、どのようなコーディングをすれば良いか
具体的に教えていただけないでしょうか。
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.