Excelデータは、ExcelTransformationDeviceクラスを使用してレポートを描画できる形式です。ExcelファイルをXlsxとCsvの2つの形式でエクスポートできます。
Excelデータは、Tablix、Tableデータ領域からのデータのみをエクスポートする機能です。データ領域の構造を保持し、レイアウトに関する機能(改ページ、累積合計など)を除外します。元のレポートの他のコントロールとデータ領域は、このエクスポートでは除外されます。FrozenRowsとFrozenColumnsプロパティにて「行/列の固定表示」の設定を行うと、エクスポートされたファイルに適用されます。詳細については、「行/列の固定表示(RDLレポート)」を参照してください。
メモ:
Xlsx形式の場合、レポートに複数のデータ領域があると、各データ領域は個別のExcelシートにエクスポートされます。
Csv形式の場合、データ領域ごとに個別のCSVファイルが作成されます。
レポートをExcel形式でエクスポートする方法の一例を以下に示します。
| Visual Basicコード(Form Loadイベント内に貼り付けます。) |
コードのコピー
|
|---|---|
' 描画するページレポートを指定します。 Dim rptPath As System.IO.FileInfo = New System.IO.FileInfo("..\..\PageReport1.rdlx") Dim pageReport As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(rptPath) ' 出力先のディレクトリを作成します。 Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyCsvData") outputDirectory.Create() ' エクスポートの各種設定を行います。 Dim settings = New GrapeCity.ActiveReports.Export.Excel.Page.Settings() settings.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.ExcelDataFileFormat.Csv settings.Csv.ColumnsDelimiter = "," settings.Csv.Encoding = System.Text.Encoding.UTF8 settings.Csv.NoHeader = False settings.Csv.QuotationSymbol = """"c settings.Csv.RowsDelimiter = vbCrLf ' 描画拡張機能を設定して、レポートを描画します。 Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, "Sample") ' 出力ファイルがすでに存在する場合は上書きします。 outputProvider.OverwriteOutputFile = True pageReport.Document.Render(New GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice(), outputProvider, settings) |
|
| C#コード(Form Loadイベント内に貼り付けます。) |
コードのコピー
|
|---|---|
// 描画するページレポートを指定します。 System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\PageReport1.rdlx"); GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath); // 出力先のディレクトリを作成します。 System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyCsvData"); outputDirectory.Create(); // エクスポートの各種設定を行います。 var settings = new GrapeCity.ActiveReports.Export.Excel.Page.Settings(); settings.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.ExcelDataFileFormat.Csv; settings.Csv.ColumnsDelimiter = ","; settings.Csv.Encoding = Encoding.UTF8; settings.Csv.NoHeader = false; settings.Csv.QuotationSymbol = '"'; settings.Csv.RowsDelimiter = "\r\n"; // 描画拡張機能を設定して、レポートを描画します。 GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, "Sample"); // 出力ファイルがすでに存在する場合は上書きします。 outputProvider.OverwriteOutputFile = true; pageReport.Document.Render(new GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice(), outputProvider, settings) |
|
| Visual Basicコード(Form Loadイベント内に貼り付けます。) |
コードのコピー
|
|---|---|
' 描画するページレポートを指定します。 Dim rptPath As System.IO.FileInfo = New System.IO.FileInfo("..\..\PageReport1.rdlx") Dim pageReport As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(rptPath) ' 出力先のディレクトリを作成します。 Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyExcelData") outputDirectory.Create() ' エクスポートの各種設定を行います。 Dim settings = New GrapeCity.ActiveReports.Export.Excel.Page.Settings() settings.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.ExcelDataFileFormat.Xlsx settings.Xlsx.AllowImages = True settings.Xlsx.UseCompression = True settings.Xlsx.OpenXmlStandard = GrapeCity.ActiveReports.Export.Excel.Page.OpenXmlStandard.Transitional settings.Xlsx.Security.ReadOnlyRecommended = True ' 描画拡張機能を設定して、レポートを描画します。 Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, "Sample") ' 出力ファイルがすでに存在する場合は上書きします。 outputProvider.OverwriteOutputFile = True pageReport.Document.Render(New GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice(), outputProvider, settings) |
|
| C#コード(Form Loadイベント内に貼り付けます。) |
コードのコピー
|
|---|---|
// 描画するページレポートを指定します。 System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\PageReport1.rdlx"); GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath); // 出力先のディレクトリを作成します。 System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyExcelData"); outputDirectory.Create(); // エクスポートの各種設定を行います。 var settings = new GrapeCity.ActiveReports.Export.Excel.Page.Settings(); settings.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.ExcelDataFileFormat.Xlsx; settings.Xlsx.AllowImages = true; settings.Xlsx.UseCompression = true; settings.Xlsx.OpenXmlStandard = GrapeCity.ActiveReports.Export.Excel.Page.OpenXmlStandard.Transitional; settings.Xlsx.Security.ReadOnlyRecommended = true; // 描画拡張機能を設定して、レポートを描画します。 GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, "Sample"); // 出力ファイルがすでに存在する場合は上書きします。 outputProvider.OverwriteOutputFile = true; pageReport.Document.Render(new GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice(), outputProvider, settings); |
|
ActiveReportsには、レポートをExcelデータにどのようにレンダリングするかを制御するオプションが用意されています。
| プロパティ | 説明 |
|---|---|
| Csv | Csvに関するプロパティを指定します。以下のCSVエクスポート(描画拡張機能)のプロパティを参照してください。 |
| FileFormat | 出力ファイルにCSV形式とOpen XML形式のどちらを使用するかを示します。 |
| Xlsx | Open XMLに関するプロパティを指定します。以下のXlsxエクスポート(描画拡張機能)のプロパティを参照してください。 |
| プロパティ | 説明 |
|---|---|
| ColumnsDelimiter | 列区切り文字を設定または返します。 |
| Encoding | 出力のエンコーディングスキーマを指定します。 |
| NoHeader | 出力からヘッダ行を除外するかどうかを設定します。 |
| QuotationSymbol | 結果を囲むための修飾子文字を設定または返します。 |
| RowsDelimiter | 行区切り文字を設定または返します。 |
| プロパティ | 説明 |
|---|---|
| AllowImages | 画像を許可するか、データのみを許可するかを示します。 |
| Author | エクスポートされたExcelファイルの「作成者」プロパティを設定します。 |
| AutoRowsHeight | 行の高さをエクスポートするか、自動の高さを指定するかを示します。 |
| Categories | エクスポートされたExcelファイルの「分類」プロパティを設定します。 |
| OpenXmlStandard |
Xlsx形式のファイルをエクスポートするときのOpen XMLドキュメントの適合レベルを指定します。次の値から選択できます。
|
| RightToLeft |
シートを右から左方向に表示します。 |
| Security | ドキュメントセキュリティを初期化するExcelRenderingExtensionSecurityオブジェクトを返します。 |
| Title | エクスポートされたExcelファイルの「タイトル」プロパティを設定します。 |
| UseCompression | Xlsx形式のファイルをエクスポートするとき圧縮するかどうかを示します。 |