True DBGrid for WinForms
エクスポート

グリッドデータを文字区切りテキスト、ExcelHTMLPDF、または RTF ファイルとしてエクスポートできます。次の表は、各ファイルタイプのエクスポートに使用するメソッドの説明です。

ファイルタイプ メソッド 説明
すべて ExportTo エクスポート形式を選択するためのダイアログを開きます。
文字区切りテキスト ExportToDelimitedFile グリッドの指定された行を指定されたファイルに文字区切りテキストとしてエクスポートします。
Excel ExportToExcel グリッドを Excel ファイルにエクスポートします。
HTML ExportToHTML グリッドを HTMLファイルにエクスポートします。
PDF ExportToPDF グリッドを PDFファイルにエクスポートします。
RTF ExportToRTF グリッドを RTF ファイルにエクスポートします。
Note: TrueDBGrid's export and printing features uses the C1.Win.Printing NuGet package, which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The PrintDocument library provides the PrintDocument and MultiDocument components, the PrintPreview library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and RibbonPreview  provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by  individual library references in the C1.Win.Printing nuget.

有効なすべてのファイルタイプにエクスポートする

ExportTo メソッドを設定するには、エクスポートボタンの Click イベントに次のコードを追加します。

C#
コードのコピー
this.c1TrueDBGrid1.ExportTo();

このトピックの作業結果

エクスポートボタンをクリックすると、TrueDBGrid 印刷のオプションダイアログが表示されます。

  1. アクションドロップダウンリストで、メタファイル、画像ファイルなどのファイルタイプを選択します。
  2. ファイル名ボックスの横にある省略符ボタンをクリックして、エクスポート先ダイアログを開きます。ファイルを保存する場所を参照し、ファイル名ボックスにファイル名を入力します。OKをクリックして、エクスポート先ダイアログを閉じます。
  3. ページヘッダおよびページフッタで、ヘッダ テキストとフッタ テキストを追加します。
  4. OKをクリックして、ファイルをエクスポートします。

    最終出力は、次の図のように表示されます。


文字区切りテキストにエクスポートする

ExportToDelimitedFileメソッドを設定するには、エクスポートボタンの Click イベントに次のコードを追加します。

C#
コードのコピー
private void button1_Click(object sender, EventArgs e)
        {
            c1TrueDBGrid1.ExportToDelimitedFile(@"c:\temp\composers.csv", C1.Win.C1TrueDBGrid.RowSelectorEnum.AllRows, ",");
        }
Note: TrueDBGrid's export and printing features uses the C1.Win.Printing NuGet package, which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The PrintDocument library provides the PrintDocument and MultiDocument components, the PrintPreview library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and RibbonPreview  provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by  individual library references in the C1.Win.Printing nuget.

エクスポートボタンをクリックすると、一時ディレクトリに文字区切りテキストファイルが作成されます。ファイル内の各値はカンマで区切られます。


Excel にエクスポートする

TrueDBGrid allows exporting grid data to Microsoft Excel format by using either of the following methods:

It is important to note that time taken to export grid data to Excel format is very small when using the SaveExcel method. In comparison, the ExportToExcel method takes much longer to export data.

To set the SaveExcel method, add the following code to the Click event of the Export button:

C#
コードのコピー
c1TrueDBGrid1.SaveExcel("../../GridData.xlsx");

Clicking the Export button creates an Excel file as given below:

C#
Copy Code
this.c1TrueDBGrid1.SaveExcel("../../GridData.xlsx");
   

To set the ExportToExcel method, add the following code to the Click event of the Export button:

C#
コードのコピー
c1TrueDBGrid1.ExportToExcel(@"c:\temp\composers.xls");
C#
Copy Code
this.c1TrueDBGrid1.ExportToExcel(@"c:\temp\composers.xls");
Note: TrueDBGrid's export and printing features uses the C1.Win.Printing NuGet package, which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The PrintDocument library provides the PrintDocument and MultiDocument components, the PrintPreview library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and RibbonPreview  provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by  individual library references in the C1.Win.Printing nuget.

Clicking the Export button creates an Excel file in the temp directory indicated in the code above:

HTML にエクスポートする

ExportToHTMLメソッドを設定するには、エクスポートボタンの Click イベントに次のコードを追加します。

C#
Copy Code
c1TrueDBGrid1.ExportToHTML(@"c:\temp\composers.html");
Note: TrueDBGrid's export and printing features uses the C1.Win.Printing NuGet package, which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The PrintDocument library provides the PrintDocument and MultiDocument components, the PrintPreview library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and RibbonPreview  provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by  individual library references in the C1.Win.Printing nuget.

エクスポートボタンをクリックすると、一時ディレクトリに HTML ファイルが作成されます。


PDF にエクスポートする

ExportToPDFメソッドを設定するには、エクスポートボタンの Click イベントに次のコードを追加します。

C#
コードのコピー
c1TrueDBGrid1.ExportToPDF(@"c:\temp\composers.pdf");
Note: TrueDBGrid's export and printing features uses the C1.Win.Printing NuGet package, which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The PrintDocument library provides the PrintDocument and MultiDocument components, the PrintPreview library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and RibbonPreview  provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by  individual library references in the C1.Win.Printing nuget.

エクスポート ボタンをクリックすると、一時ディレクトリに PDF ファイルが作成されます。


RTF にエクスポートする

ExportToRTFメソッドを設定するには、エクスポートボタンの Click イベントに次のコードを追加します。

C#
コードのコピー
c1TrueDBGrid1.ExportToRTF(@"c:\temp\composers.rtf");
Note: TrueDBGrid's export and printing features uses the C1.Win.Printing NuGet package, which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The PrintDocument library provides the PrintDocument and MultiDocument components, the PrintPreview library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and RibbonPreview  provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by  individual library references in the C1.Win.Printing nuget.

エクスポートボタンをクリックすると、一時ディレクトリに RTF ファイルが作成されます。