ActiveReportsは、PDF、Excel、TIFF、RTF、TEXTの形式でのレポートカスタムエクスポートを設定するコンポーネントを提供します。同様にHTMLへのエクスポートや、「HTMLの出力のカスタマイズ 」を行うこともできます。
Webプロジェクトにレポートとエクスポート参照を追加する
GrapeCity.ActiveReports.Export.Pdf.ja
GrapeCity.ActiveReports.Export.Xml.ja
GrapeCity.ActiveReports.Export.Excel.ja
GrapeCity.ActiveReports.Export.Word.ja
GrapeCity.ActiveReports.Export.Image.jaレポートをPDFにエクスポートするためにWebフォームにコードを追加する
Visual Basic
| Visual Basicコード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
Dim m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader(Server.MapPath("\SectionReport1.rpx"))
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim PdfExport1 As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
PdfExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf")
Response.BinaryWrite(m_stream.ToArray())
Response.End()
|
|
C#
| C#コード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.Run(); |
|
メモ: プレビュー後に印刷ダイアログをすぐに表示するには、次のコードを上記のコードに追加します。
| Visual Basicコード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
pdfExport1.Options.OnlyForPrint = True
|
|
| C#コード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
pdfExport1.Options.OnlyForPrint = true;
|
|
レポートをExcelにエクスポートするためにWebフォームにコードを追加する
Visual Basic
| Visual Basicコード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
Dim m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader(Server.MapPath("\SectionReport1.rpx"))
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()
XlsExport1.MinColumnWidth = 0.5
XlsExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "inline; filename=MyExport.xls")
Response.BinaryWrite(m_stream.ToArray())
Response.End()
|
|
C#
| C#コード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
|
|
レポートをTIFFにエクスポートするためにWebフォームにコードを追加する
Visual Basic
| Visual Basicコード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
Dim m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader(Server.MapPath("\SectionReport1.rpx"))
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim TiffExport1 As New GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport
TiffExport1.CompressionScheme = GrapeCity.ActiveReports.Export.Image.Tiff.Section.CompressionScheme.None
TiffExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "image/tiff"
Response.AddHeader("content-disposition", "inline; filename=MyExport.tiff")
Response.BinaryWrite(m_stream.ToArray())
Response.End()
|
|
C#
| C#コード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport tiffExport1 = new GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport();
tiffExport1.CompressionScheme = GrapeCity.ActiveReports.Export.Image.Tiff.Section.CompressionScheme.None;
tiffExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "image/tiff";
Response.AddHeader("content-disposition","inline; filename=MyExport.tiff");
Response.BinaryWrite(m_stream.ToArray());
Response.End();
|
|
レポートをRTFにエクスポートするためにWebフォームにコードを追加する
Visual Basic
| Visual Basicコード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
Dim m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader(Server.MapPath("\SectionReport1.rpx"))
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim RtfExport1 As New GrapeCity.ActiveReports.Export.Word.Section.RtfExport
RtfExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "application/msword"
Response.AddHeader("content-disposition", "inline; filename=MyExport.rtf")
Response.BinaryWrite(m_stream.ToArray())
Response.End()
|
|
C#
| C#コード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Word.Section.RtfExport rtfExport1 = new GrapeCity.ActiveReports.Export.Word.Section.RtfExport();
rtfExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "application/msword";
Response.AddHeader("content-disposition","inline; filename=MyExport.rtf");
Response.BinaryWrite(m_stream.ToArray());
Response.End();
|
|
レポートをTextにエクスポートするためにWebフォームにコードを追加する
Visual Basic
| Visual Basicコード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
Dim m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader(Server.MapPath("\SectionReport1.rpx"))
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim TextExport1 As New GrapeCity.ActiveReports.Export.Xml.Section.TextExport
TextExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "text/plain"
Response.AddHeader("content-disposition", "attachment; filename=MyExport.txt")
Response.BinaryWrite(m_stream.ToArray())
Response.End()
|
|
C#
| C#コード (Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Xml.Section.TextExport textExport1 = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
textExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", "attachment; filename=MyExport.txt");
Response.BinaryWrite(m_stream.ToArray());
Response.End();
|
|
プロジェクトを実行する
[F5]キーを押して、プロジェクトを実行します。