ActiveReportsでは、一般的によく使用されているPDF、HTML、Excel、Image、Wordの各形式でレポートをエクスポートすることができます。
このトピックでは、以下のタスクを行います。
メモ: このチュートリアルではページレポートを使用していますが、RDLレポートを使用した場合も同様の手順でエクスポートすることが可能です。
Visual StudioプロジェクトにActiveReportsを追加する
GrapeCity.ActiveReports.Export.Pdf.ja
GrapeCity.ActiveReports.Export.Html.ja
GrapeCity.ActiveReports.Export.Excel.ja
GrapeCity.ActiveReports.Export.Word.ja
GrapeCity.ActiveReports.Export.Image.ja
GrapeCity.ActiveReports.Export.Xml.ja詳細については、「クイックスタート」を参照してくだざい。
PDFの描画拡張機能を使用してレポートをエクスポートするためのコードをWebフォームに追加する
Visual Basic
| Visual Basicコード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
'エクスポートするページレポートのインスタンスを生成します。
Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)
'描画拡張機能でレポートをエクスポートします。
Dim pdfRenderingExtension As New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension()
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
reportDocument.Render(pdfRenderingExtension, outputProvider)
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf")
Dim ms As New System.IO.MemoryStream()
CType(outputProvider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()
|
|
C#
| C#コード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
// エクスポートするページレポートのインスタンスを生成します。
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
// 描画拡張機能でレポートをエクスポートします。
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
reportDocument.Render(pdfRenderingExtension, outputProvider);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
|
|
メモ: PDFエクスポートを使用する場合、アプリケーションに手動でライセンスを供与する必要があります。詳細については、「アプリケーションのライセンスの組み込み」を参照してください。
メモ : プレビュー後に印刷ダイアログをすぐに表示するには、以下のコードを使用します。
| Visual Basicコード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
'上記のコードの、_reportRuntime.Render(_renderingExtension, _provider)行を次の行に貼り換えます。 Dim s As New GrapeCity.ActiveReports.Export.Pdf.Page.Settings() setting.PrintOnOpen = True reportDocument.Render(pdfRenderingExtension, outputProvider,setting) |
|
| C#コード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
//上記のコードの、_reportRuntime.Render(_renderingExtension, _provider)行を次の行に貼り換えます。 GrapeCity.ActiveReports.Export.Pdf.Page.Settings setting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();setting.PrintOnOpen = true;reportDocument.Render(pdfRenderingExtension, outputProvider,setting); |
|
HTMLの描画拡張機能を使用してレポートをエクスポートするためのコードをWebフォームに追加する
Visual Basic
| Visual Basicコード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
'エクスポートするページレポートのインスタンスを生成します。
Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)
'描画拡張機能でレポートをエクスポートします。
Dim htmlRenderingExtension As New GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension()
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
Dim setting As New GrapeCity.ActiveReports.Export.Html.Page.Settings()
setting.Mode = GrapeCity.ActiveReports.Core.Export.Html.Page.RenderMode.Galley
setting.MhtOutput = True
reportDocument.Render(htmlRenderingExtension, outputProvider, setting)
Response.ContentType = "message/rfc822"
Response.AddHeader("content-disposition", "inline;filename=MyExport.mht")
Dim ms As New System.IO.MemoryStream()
CType(outputProvider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()
|
|
C#
| C#コード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
// エクスポートするページレポートのインスタンスを生成します。
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
// 描画拡張機能でレポートをエクスポートします。
GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension htmlRenderingExtension = new GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension();
|
|
Excelの描画拡張機能を使用してレポートをエクスポートするためのコードをWebフォームに追加する
Visual Basic
| Visual Basicコード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
'エクスポートするページレポートのインスタンスを生成します。
Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)
' 描画するファイルの設定を行います。
Dim excelSetting As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings()
excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx
Dim setting As GrapeCity.ActiveReports.Extensibility.Rendering.ISettings = excelSetting
'描画拡張機能でレポートをエクスポートします。
Dim excelRenderingExtension As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension()
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings())
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "inline;filename=MyExport.xls")
Dim ms As New System.IO.MemoryStream()
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.[End]()
|
|
C#
| C#コード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
// エクスポートするページレポートのインスタンスを生成します。
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
// 描画するファイルの設定を行います。
GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx;
GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;
// 描画拡張機能でレポートをエクスポートします。
GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings());
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
|
|
Wordの描画拡張機能を使用してレポートをエクスポートするためのコードをWebフォームに追加する
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.HTML
Visual Basic
| Visual Basicコード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
' 描画するレポートを読み込みします。
Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)
' 描画拡張機能を設定し、レポートを描画します。
Dim wordRenderingExtension As New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension()
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
' FileFormatプロパティを.OOXMLに設定します。
Dim wordSetting As New GrapeCity.ActiveReports.Export.Word.Page.Settings()
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML
reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting)
Response.ContentType = "application/msword"
Response.AddHeader("content-disposition", "inline;filename=MyExport.docx")
Dim ms As New System.IO.MemoryStream()
CType(outputProvider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()
|
|
C#
| C#コード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
// 描画するレポートを読み込みします。
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
// 描画拡張機能を設定し、レポートを描画します。
GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
// FileFormatプロパティを.OOXMLに設定します。
GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings();
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML;
reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting);
Response.ContentType = "application/msword";
Response.AddHeader("content-disposition", "inline;filename=MyExport.docx");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
|
|
Imageの描画拡張機能を使用してレポートをエクスポートするためのコードをWebフォームに追加する
Visual Basic
| Visual Basicコード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
' エクスポートするページレポートのインスタンスを生成します。
Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)
' 描画拡張機能でレポートをエクスポートします。
Dim imageRenderingExtension As New GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension()
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
Dim setting As New GrapeCity.ActiveReports.Export.Image.Page.Settings()
setting.ImageType = GrapeCity.ActiveReports.Export.Image.Page.Renderers.ImageType.JPEG
reportDocument.Render(imageRenderingExtension, outputProvider, setting)
Response.ContentType = "image/jpeg"
Response.AddHeader("content-disposition", "inline;filename=MyExport.jpg")
Dim ms As New System.IO.MemoryStream()
' レポートの最初のページを取得します。
CType(outputProvider.GetSecondaryStreams()(0).OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()
|
|
C#
| C#コード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
// エクスポートするページレポートのインスタンスを生成します。
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
// 描画拡張機能でレポートをエクスポートします。
GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension imageRenderingExtension = new GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Image.Page.Settings setting = new GrapeCity.ActiveReports.Export.Image.Page.Settings();
setting.ImageType = GrapeCity.ActiveReports.Export.Image.Page.Renderers.ImageType.JPEG;
reportDocument.Render(imageRenderingExtension, outputProvider, setting);
Response.ContentType = "image/jpeg";
Response.AddHeader("content-disposition", "inline;filename=MyExport.jpg");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
// レポートの最初のページを取得します。
outputProvider.GetSecondaryStreams()[0].OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
|
|
XMLの描画拡張機能を使用してレポートをエクスポートするためのコードをWebフォームに追加する
Visual Basic
| Visual Basicコード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
' エクスポートするページレポートのインスタンスを生成します。
Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)
' 描画拡張機能でレポートをエクスポートします。
Dim xmlRenderingExtension As New GrapeCity.ActiveReports.Export.Xml.Page.XmlRenderingExtension()
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
reportDocument.Render(xmlRenderingExtension, outputProvider)
Response.ContentType = "application/xml"
Response.AddHeader("content-disposition", "inline;filename=MyExport.xml")
Dim ms As New System.IO.MemoryStream()
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.[End]()
|
|
C#
| C#コード(Page Loadイベント内に貼り付けます) |
コードのコピー
|
|---|---|
// エクスポートするページレポートのインスタンスを生成します。
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
// 描画拡張機能でレポートをエクスポートします。
GrapeCity.ActiveReports.Export.Xml.Page.XmlRenderingExtension xmlRenderingExtension = new GrapeCity.ActiveReports.Export.Xml.Page.XmlRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
reportDocument.Render(xmlRenderingExtension, outputProvider);
Response.ContentType = "application/xml";
Response.AddHeader("content-disposition", "inline;filename=MyExport.xml");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
|
|
プロジェクトを実行する
[F5]キーを押し、アプリケーションを実行します。