サーバー側で印刷を行う
Visual Basic
| Visual Basic コード |
コードのコピー
|
|---|---|
Dim rpt As New SectionReport1 rpt.Run() rpt.Document.Print(False, False, False) |
|
C#
| C# コード |
コードのコピー
|
|---|---|
SectionReport1 rpt = new SectionReport1(); rpt.Run(); rpt.Document.Print(false, false, false); |
|
サーバー側から印刷するには、以下の条件を満たしている必要があります。
![]() |
注意: ASP.NETが実行されるデフォルトの権限は、IIS7やIIS8の場合は「NETWORK SERVICEアカウント」となります。IIS7.5の場合は、「IIS_IUSRS」に権限が必要です。 なお、マシン上にAdministrator権限でインストールされたプリンタは、ローカルプリンタの情報のみが、これらのアカウントにも引き継がれます。従いまして、サーバーマシン上にネットワークプリンタしかインストールされていない場合、これらのアカウントでは「インストールされているプリンタが存在しない」という状態になるため、注意が必要です。 |
ローカルプリンタではなく、ネットワークプリンタを利用する場合は、下記の設定が必要になります。
ネットワークプリンタに印刷する際に必要な設定
具体的な手順は、Microsoft社の下記サイトにて紹介されております。
[IIS]ASP によるサーバ側での印刷方法について
http://support.microsoft.com/default.asx?scid=kb;ja;419321
Web上で動的なレポートを作成する(1)
ActiveReportsのイベント内で、Sessionオブジェクトの内容を直接参照するような機能は用意されていません。WebForm上で入力された値などを、生成するレポートに反映させる方法としては、下記のような方法が考えられます。
Visual Basic
| Visual Basic コード |
コードのコピー
|
|---|---|
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rpt As New SectionReport1()
CType(rpt.Sections("PageHeader").Controls("Label1"), GrapeCity.ActiveReports.SectionReportModel.Label).Text = "abcd"
rpt.Run()
WebViewer1.Report = rpt
End Sub
|
|
C#
| C# コード |
コードのコピー
|
|---|---|
private void Page_Load(object sender, System.EventArgs e)
{
SectionReport rpt = new SectionReport();
((GrapeCity.ActiveReports.SectionReportModel.Label)(rpt.Sections["PageHeader"].Controls["Label1"])).Text = "label";
rpt.Run();
WebViewer1.Report = rpt;
}
|
|
Visual Basic
| Visual Basic コード |
コードのコピー
|
|---|---|
Public Param1 As String
Public Param2 As String
Private Sub SectionReport1_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ReportStart
' 渡された文字列をTextBoxに設定します。
TextBox1.Text = Param1
TextBox2.Text = Param2
End Sub
|
|
Visual Basic
| Visual Basic コード |
コードのコピー
|
|---|---|
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rpt As SectionReport1 = New SectionReport1()
' WebControlのTextBox上のデータを、レポートに渡します。
rpt.Param1 = TextBox1.Text
rpt.Param2 = TextBox2.Text
rpt.Run()
WebViewer1.Report = rpt
End Sub
|
|
C#
| C# コード |
コードのコピー
|
|---|---|
public string Param1;
public string Param2;
private void PageHeader_Format(object sender, System.EventArgs eArgs)
{
// 渡された文字列をTextBoxに設定します。
TextBox1.Text = Param1;
TextBox2.Text = Param2;
}
|
|
C#
| C# コード |
コードのコピー
|
|---|---|
private void Page_Load(object sender, System.EventArgs e)
{
SectionReport1 rpt = new SectionReport1();
// WebControlのTextBox上のデータを、レポートに渡します。
rpt.Param1 = TextBox1.Text;
rpt.Param2 = TextBox2.Text;
rpt.Run();
WebViewer1.Report = rpt;
}
|
|
レポート内でコンストラクタを定義し、レポートインスタンス生成時に値を渡す方法です。
Visual Basic
| Visual Basicコード |
コードのコピー
|
|---|---|
Public Class SectionReport1 Inherits SectionReport
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
' コンストラクタを定義します。
Dim myStrInput As String
Public Sub New(ByVal StrInput As String)
MyBase.New()
InitializeComponent()
myStrInput = StrInput
End Sub
Private Sub PageFooter_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles PageFooter.Format
' 引数として渡された文字列をTextBoxに設定します。
TextBox1.Text = myStrInput
End Sub
End Class
|
|
Visual Basic
| Visual Basicコード |
コードのコピー
|
|---|---|
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rpt As New SectionReport1(TextBox1.Text)
rpt.Run()
WebViewer1.Report = rpt
End Sub
|
|
C#
| C# コード |
コードのコピー
|
|---|---|
public class SectionReport1 : GrapeCity.ActiveReports.SectionReport
{
public SectionReport1()
{
InitializeComponent();
}
// コンストラクタを定義します。
private string myStrText;
public SectionReport1(string StrText)
{
InitializeComponent();
myStrText = StrText;
}
private void PageHeader_Format(object sender, System.EventArgs eArgs)
{
// 引数として渡された文字列をTextBoxに設定します。
TextBox1.Text = myStrText;
}
}
|
|
C#
| C# コード |
コードのコピー
|
|---|---|
private void Page_Load(object sender, System.EventArgs e)
{
SectionReport1 rpt = new SectionReport1("abcd");
rpt.Run();
WebViewer1.Report = rpt;
}
|
|
![]() |
注意: WebViewerコントロールは、Professionalの機能です。 |
Web上で動的なレポートを作成する(2)
WebForm上の条件を元に、動的にデータソースの内容を設定してレポートを作成し、WebViewerコントロール上に表示するには
レポートのデータソースを動的に設定し、レポートをWebViewerコントロールのReportプロパティに設定することで、WebForm上の任意の条件を元にレポートを作成し、表示することができます。
たとえば、WebコントロールのTextBoxに入力された文字列をSQL文としてレポートに設定し、動的にレポートを作成する場合の、最も簡単な例を以下に示します。
Visual Basic
| Visual Basicコード |
コードのコピー
|
|---|---|
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rpt As New SectionReport1
' TextBoxの文字列を、SQLプロパティに設定します。
' OleDBDataSourceを使用している場合は以下のように設定します。
CType(rpt.DataSource, GrapeCity.ActiveReports.Data.OleDBDataSource).SQL = TextBox1.Text
rpt.Restart()
rpt.Run()
WebViewer1.Report = rpt
End Sub
|
|
C#
| C#コード |
コードのコピー
|
|---|---|
private void Page_Load(object sender, System.EventArgs e)
{
SectionReport1 rpt = new SectionReport1();
// TextBoxの文字列を、SQLプロパティに設定します。
// OleDBDataSourceを使用している場合は以下のように設定します。
((GrapeCity.ActiveReports.Data.OleDBDataSource)rpt.DataSource).SQL = TextBox1.Text;
rpt.Restart();
rpt.Run();
WebViewer1.Report = rpt;
}
|
|
![]() |
注意: WebViewerコントロールは、Professionalの機能です。 |
IIS ExpressでFlashビューワのクライアントスクリプトを使用してRDFファイルが読み込みされません
開発環境でIIS Expressを使用している場合、Flashビューワのクライアントスクリプトを使用してRDFファイルを読み込むためには、IIS Expressの設定が必要です。
IIS Expressのインストールフォルダで、以下のコマンドを実行します。デフォルトでは、C:\Program Files\IIS Expressにあります。
| コマンドライン内に貼り付けます |
コードのコピー
|
|---|---|
appcmd set config /section:staticContent /+[fileExtension='.rdf',mimeType='application/octet-stream'] |
|
または、
| staticContentノードに追加します |
コードのコピー
|
|---|---|
<mimeMap fileExtension=".rdf" mimeType="application/octet-stream" /> |
|