テーブルの作成とフォーマット

テーブルの作成

スプレッドシートの利点の 1 つは、電話番号リスト、タスク リスト、取引リスト、資産または負債のリストなど、さまざまな種類のリストを作成できることです。複数のユーザーが協力して、さまざまなリストを使用、作成、および維持できます。

Aspose.Cells は、リストの作成と管理をサポートしています。

リスト オブジェクトの利点

データのリストを実際のリスト オブジェクトに変換すると、多くの利点があります。

  • 新しい行と列が自動的に含まれます。
  • リストの下部に合計行を簡単に追加して、SUM、AVERAGE、COUNT などを表示できます。
  • 右側に追加された列は、List オブジェクトに自動的に組み込まれます。
  • 行と列に基づくグラフは自動的に展開されます。
  • 行と列に割り当てられた名前付き範囲は、自動的に展開されます。
  • リストは、偶発的な行と列の削除から保護されています。

Microsoft Excel を使用してリスト オブジェクトを作成する

List オブジェクトを作成するためのデータ範囲の選択
todo:画像_代替_文章
[リストの作成] ダイアログが表示されます。
リストの作成ダイアログ
todo:画像_代替_文章
データの List オブジェクトを実装し、合計行を指定する (選択データ、 それからリスト、 に続く合計行).
リスト オブジェクトの作成
todo:画像_代替_文章

Aspose.Cells API を使用

Aspose.Cells はクラスを提供しますIワークブックMicrosoft Excel ファイルを表します。のIワークブッククラスにはIワークシートExcel ファイル内の各ワークシートにアクセスできるコレクション。

ワークシートは、Iワークシートクラス。のIワークシートクラスには、ワークシートを管理するためのさまざまなメソッドが用意されています。を作成するにはIListObjectワークシートでは、GetIListObjectsの回収方法Iワークシートクラス。実際、各 [IListObject] は、IListObjectCollectionクラスは、さらに追加[IListObject] オブジェクトを追加し、リストのセル範囲を指定するメソッド。

指定されたセル範囲に従って、Aspose.Cells オブジェクトが Aspose.Cells によって作成されます。属性を使用します (たとえば、ShowTotalsListColumnsなど) [IListObject] クラスのリストを制御します。

以下の例では、上記のセクションで Microsoft Excel を使用して作成したのと同じ Aspose.Cells API を使用して [IListObject] を作成しています。

For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Instantiate a Workbook object and open an Excel file
intrusive_ptr<IWorkbook> workbook =Factory::CreateIWorkbook(dataDir_Tables->StringAppend(new String("book1.xls")));
// Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Get the List objects collection in the first worksheet.
intrusive_ptr<IListObjectCollection> listObjects = worksheet->GetIListObjects();
// Add a List based on the data source range with headers on.
listObjects->Add(1, 1, 7, 5, true);
// Show the total row for the List.
listObjects->GetObjectByIndex(0)->SetShowTotals(true);
// Saving the Excel file
workbook->Save(dataDir_Tables->StringAppend(new String("CreatingListObjects_out.xls")));

テーブルをフォーマットする

関連するデータのグループを管理および分析するために、セルの範囲をリスト オブジェクト (Excel テーブルとも呼ばれます) に変換することができます。テーブルは、他の行や列のデータとは独立して管理される関連データを含む一連の行と列です。既定では、テーブルのすべての列のヘッダー行でフィルター処理が有効になっているため、リスト オブジェクト データをすばやくフィルター処理または並べ替えることができます。各合計行セルの集計関数のドロップダウン リストを提供するリスト オブジェクトに、合計行 (数値データの操作に役立つ集計関数の選択を提供するリスト内の特別な行) を追加できます。 Aspose.Cells は、リスト (またはテーブル) を作成および管理するためのオプションを提供します。

リスト オブジェクトの書式設定

Aspose.Cells はクラスを提供しますIワークブックMicrosoft Excel ファイルを表します。のIワークブッククラスにはIワークシートExcel ファイル内の各ワークシートにアクセスできるコレクション。

ワークシートは、Iワークシートクラス。のIワークシートクラスには、ワークシートを管理するためのさまざまなメソッドが用意されています。を作成するにはListObjectワークシートでは、IListObjectCollection を使用します。実際には、各 [IListObject]IListObjectCollection クラスのオブジェクトであり、さらに追加メソッドを使用して [IListObject] オブジェクトを追加し、含まれるセルの範囲を指定します。指定されたセル範囲に従って、ListObjectは Aspose.Cells によってワークシートに作成されます。属性を使用します (たとえば、表スタイルの種類[IListObject] クラスの ) を使用して、要件に合わせてテーブルをフォーマットします。

次の例では、サンプル データをワークシートに追加し、[IListObject] を追加して、既定のスタイルを適用します。 [IListObject] スタイルは Microsoft Excel 2007/2010 でサポートされています。

For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Instantiate a Workbook object
intrusive_ptr<IWorkbook> workbook =Factory::CreateIWorkbook();
// Obtaining the reference of the default(first) worksheet
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Obtaining Worksheet's cells collection
intrusive_ptr<ICells> cells = worksheet->GetICells();
// Setting the value to the cells
cells->GetObjectByIndex(new String("A1"))->PutValue("Employee");
cells->GetObjectByIndex(new String("B1"))->PutValue("Quarter");
cells->GetObjectByIndex(new String("C1"))->PutValue("Product");
cells->GetObjectByIndex(new String("D1"))->PutValue("Continent");
cells->GetObjectByIndex(new String("E1"))->PutValue("Country");
cells->GetObjectByIndex(new String("F1"))->PutValue("Sale");
cells->GetObjectByIndex(new String("A2"))->PutValue("David");
cells->GetObjectByIndex(new String("A3"))->PutValue("David");
cells->GetObjectByIndex(new String("A4"))->PutValue("David");
cells->GetObjectByIndex(new String("A5"))->PutValue("David");
cells->GetObjectByIndex(new String("A6"))->PutValue("James");
cells->GetObjectByIndex(new String("A7"))->PutValue("James");
cells->GetObjectByIndex(new String("A8"))->PutValue("James");
cells->GetObjectByIndex(new String("A9"))->PutValue("James");
cells->GetObjectByIndex(new String("A10"))->PutValue("James");
cells->GetObjectByIndex(new String("A11"))->PutValue("Miya");
cells->GetObjectByIndex(new String("A12"))->PutValue("Miya");
cells->GetObjectByIndex(new String("A13"))->PutValue("Miya");
cells->GetObjectByIndex(new String("A14"))->PutValue("Miya");
cells->GetObjectByIndex(new String("A15"))->PutValue("Miya");
cells->GetObjectByIndex(new String("B2"))->PutValue(1);
cells->GetObjectByIndex(new String("B3"))->PutValue(2);
cells->GetObjectByIndex(new String("B4"))->PutValue(3);
cells->GetObjectByIndex(new String("B5"))->PutValue(4);
cells->GetObjectByIndex(new String("B6"))->PutValue(1);
cells->GetObjectByIndex(new String("B7"))->PutValue(2);
cells->GetObjectByIndex(new String("B8"))->PutValue(3);
cells->GetObjectByIndex(new String("B9"))->PutValue(4);
cells->GetObjectByIndex(new String("B10"))->PutValue(4);
cells->GetObjectByIndex(new String("B11"))->PutValue(1);
cells->GetObjectByIndex(new String("B12"))->PutValue(1);
cells->GetObjectByIndex(new String("B13"))->PutValue(2);
cells->GetObjectByIndex(new String("B14"))->PutValue(2);
cells->GetObjectByIndex(new String("B15"))->PutValue(2);
cells->GetObjectByIndex(new String("C2"))->PutValue("Maxilaku");
cells->GetObjectByIndex(new String("C3"))->PutValue("Maxilaku");
cells->GetObjectByIndex(new String("C4"))->PutValue("Chai");
cells->GetObjectByIndex(new String("C5"))->PutValue("Maxilaku");
cells->GetObjectByIndex(new String("C6"))->PutValue("Chang");
cells->GetObjectByIndex(new String("C7"))->PutValue("Chang");
cells->GetObjectByIndex(new String("C8"))->PutValue("Chang");
cells->GetObjectByIndex(new String("C9"))->PutValue("Chang");
cells->GetObjectByIndex(new String("C10"))->PutValue("Chang");
cells->GetObjectByIndex(new String("C11"))->PutValue("Geitost");
cells->GetObjectByIndex(new String("C12"))->PutValue("Chai");
cells->GetObjectByIndex(new String("C13"))->PutValue("Geitost");
cells->GetObjectByIndex(new String("C14"))->PutValue("Geitost");
cells->GetObjectByIndex(new String("C15"))->PutValue("Geitost");
cells->GetObjectByIndex(new String("D2"))->PutValue("Asia");
cells->GetObjectByIndex(new String("D3"))->PutValue("Asia");
cells->GetObjectByIndex(new String("D4"))->PutValue("Asia");
cells->GetObjectByIndex(new String("D5"))->PutValue("Asia");
cells->GetObjectByIndex(new String("D6"))->PutValue("Europe");
cells->GetObjectByIndex(new String("D7"))->PutValue("Europe");
cells->GetObjectByIndex(new String("D8"))->PutValue("Europe");
cells->GetObjectByIndex(new String("D9"))->PutValue("Europe");
cells->GetObjectByIndex(new String("D10"))->PutValue("Europe");
cells->GetObjectByIndex(new String("D11"))->PutValue("America");
cells->GetObjectByIndex(new String("D12"))->PutValue("America");
cells->GetObjectByIndex(new String("D13"))->PutValue("America");
cells->GetObjectByIndex(new String("D14"))->PutValue("America");
cells->GetObjectByIndex(new String("D15"))->PutValue("America");
cells->GetObjectByIndex(new String("E2"))->PutValue("China");
cells->GetObjectByIndex(new String("E3"))->PutValue("India");
cells->GetObjectByIndex(new String("E4"))->PutValue("Korea");
cells->GetObjectByIndex(new String("E5"))->PutValue("India");
cells->GetObjectByIndex(new String("E6"))->PutValue("France");
cells->GetObjectByIndex(new String("E7"))->PutValue("France");
cells->GetObjectByIndex(new String("E8"))->PutValue("Germany");
cells->GetObjectByIndex(new String("E9"))->PutValue("Italy");
cells->GetObjectByIndex(new String("E10"))->PutValue("France");
cells->GetObjectByIndex(new String("E11"))->PutValue("U.S.");
cells->GetObjectByIndex(new String("E12"))->PutValue("U.S.");
cells->GetObjectByIndex(new String("E13"))->PutValue("Brazil");
cells->GetObjectByIndex(new String("E14"))->PutValue("U.S.");
cells->GetObjectByIndex(new String("E15"))->PutValue("U.S.");
cells->GetObjectByIndex(new String("F2"))->PutValue(2000);
cells->GetObjectByIndex(new String("F3"))->PutValue(500);
cells->GetObjectByIndex(new String("F4"))->PutValue(1200);
cells->GetObjectByIndex(new String("F5"))->PutValue(1500);
cells->GetObjectByIndex(new String("F6"))->PutValue(500);
cells->GetObjectByIndex(new String("F7"))->PutValue(1500);
cells->GetObjectByIndex(new String("F8"))->PutValue(800);
cells->GetObjectByIndex(new String("F9"))->PutValue(900);
cells->GetObjectByIndex(new String("F10"))->PutValue(500);
cells->GetObjectByIndex(new String("F11"))->PutValue(1600);
cells->GetObjectByIndex(new String("F12"))->PutValue(600);
cells->GetObjectByIndex(new String("F13"))->PutValue(2000);
cells->GetObjectByIndex(new String("F14"))->PutValue(500);
cells->GetObjectByIndex(new String("F15"))->PutValue(900);
// Adding a new List Object to the worksheet
worksheet->GetIListObjects()->Add(new String("A1"), new String("F15"), true);
intrusive_ptr<IListObject> listObject = worksheet->GetIListObjects()->GetObjectByIndex(0);
// Adding Default Style to the table
listObject->SetTableStyleType(TableStyleType_TableStyleMedium10);
// Show Total
listObject->SetShowTotals(true);
// Saving the Excel file
workbook->Save(dataDir_Tables->StringAppend(new String("FormatTable_out.xlsx")));