エクセル表の作成と操作
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsを使用すると、新規または既存のリストオブジェクトやテーブルを作成および操作できます。リストオブジェクトやテーブルのさまざまなメソッドを使用できます(ヘッダー行スタイル、列ストライプ、スタイルタイプ、小計の表示など)、またテーブルの個々の列と作成名を操作して、最小値、最大値、カウント、平均、合計などの計算関数を設定できます。
エクセル表の作成と操作
次のサンプルコードは、サンプルエクセルファイル を読み込んで、範囲A1:H10にリストオブジェクトまたはテーブルを作成し、そのさまざまなメソッドを使用し小計を表示します。その後、テーブルの3番目、4番目、5番目の列の合計関数をそれぞれ最小値、最大値、カウントに設定し、出力エクセルファイル を書き込みます。サンプルコードの実行後、サンプルエクセルファイル に対するサンプルコードの効果を示すスクリーンショットが以下にあります。
サンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String dirPath(u"..\\Data\\TechnicalArticles\\"); | |
//Output directory path | |
U16String outPath(u"..\\Data\\Output\\"); | |
//Path of input excel file | |
U16String sampleCreateAndManipulateExcelTable = dirPath + u"sampleCreateAndManipulateExcelTable.xlsx"; | |
//Path of output excel file | |
U16String outputCreateAndManipulateExcelTable = outPath + u"outputCreateAndManipulateExcelTable.xlsx"; | |
//Load the sample excel file | |
Workbook wb(sampleCreateAndManipulateExcelTable); | |
//Access first worksheet | |
Worksheet ws = wb.GetWorksheets().Get(0); | |
//Add table i.e. list object | |
int idx = ws.GetListObjects().Add(u"A1", u"H10", true); | |
//Access the newly added list object | |
ListObject lo = ws.GetListObjects().Get(idx); | |
//Use its display methods | |
lo.SetShowHeaderRow(true); | |
lo.SetShowTableStyleColumnStripes(true); | |
lo.SetShowTotals(true); | |
//Set its style | |
lo.SetTableStyleType(TableStyleType::TableStyleLight12); | |
//Set total functions of 3rd, 4th and 5th columns | |
lo.GetListColumns().Get(2).SetTotalsCalculation(TotalsCalculation::Min); | |
lo.GetListColumns().Get(3).SetTotalsCalculation(TotalsCalculation::Max); | |
lo.GetListColumns().Get(4).SetTotalsCalculation(TotalsCalculation::Count); | |
//Save the output excel file | |
wb.Save(outputCreateAndManipulateExcelTable); | |
Aspose::Cells::Cleanup(); |