グリッドからのデータのエクスポート

グリッド コンテンツのエクスポート

特定の DataTable へのエクスポート

グリッドの内容を特定の DataTable オブジェクトにエクスポートするには、次の手順に従ってください: Aspose.Cells.GridDesktop コントロールを.

  • 必要に応じて特定の DataTable オブジェクトを作成します。
  • 選択したデータのエクスポートワークシート指定した DataTable オブジェクトに。

以下の例では、内部に 4 つの列を持つ特定の DataTable オブジェクトを作成しました。最後に、ワークシート データ (69 行 4 列の最初のセルから開始) を、作成済みの DataTable オブジェクトにエクスポートしました。

例:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Creating a new DataTable object
DataTable dataTable = new DataTable();
// Adding specific columns to the DataTable object
dataTable.Columns.Add("ProductName", System.Type.GetType("System.String"));
dataTable.Columns.Add("CategoryName", System.Type.GetType("System.String"));
dataTable.Columns.Add("QuantityPerUnit", System.Type.GetType("System.String"));
dataTable.Columns.Add("UnitsInStock", System.Type.GetType("System.Int32"));
// Exporting the data of the first worksheet of the Grid to the specific DataTable object
dataTable = gridDesktop1.Worksheets[0].ExportDataTable(dataTable, 0, 0, 69, 4, true);

新しい DataTable へのエクスポート

場合によっては、開発者が独自の DataTable オブジェクトを作成することに関心がなく、ワークシート データを新しい DataTable オブジェクトにエクスポートするだけの単純な必要性がある場合があります。開発者にとっては、ワークシート データをエクスポートするのが最も簡単な方法です。

以下の例では、ExportDataTable メソッドの使用法を説明するために別の方法を試しました。現在アクティブなワークシートの参照を取得し、そのアクティブなワークシートの完全なデータを新しい DataTable オブジェクトにエクスポートしました。現在、この DataTable オブジェクトは、開発者が望むあらゆる方法で使用できます。例として、開発者はこの DataTable オブジェクトを DataGrid にバインドしてデータを表示できます。

例:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the reference of the worksheet that is currently active
Worksheet sheet = gridDesktop1.GetActiveWorksheet();
//Getting the total number of rows and columns inside the worksheet
int totalRows = sheet.RowsCount;
int totalCols = sheet.ColumnsCount;
// Exporting the data of the active worksheet to a new DataTable object
DataTable table = sheet.ExportDataTable(0, 0, totalRows, totalCols, false, true);