テーブルおよび範囲

紹介

Microsoft Excelでテーブルを作成し、その機能を使用せずにテーブルのデータを保持したい場合があります。代わりに、テーブルのように見えるものが欲しい場合があります。フォーマットを失わずにテーブル内のデータを保持するには、テーブルを通常のデータの範囲に変換します。 Aspose.Cellsは、テーブルやリストオブジェクトのMicrosoft Excelのこの機能をサポートしています。

Microsoft Excel の使用

表をフォーマットを保持したまま範囲に素早く変換するには、範囲に変換 機能を使用します。Microsoft Excel 2007/2010では:

  1. 表内のどこかをクリックして、アクティブなセルが表の列内にあることを確認します。
  2. デザイン タブの ツール グループで、範囲に変換 をクリックします。

Aspose.Cellsの使用

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Open an existing file that contains a table/list object in it
Workbook wb = new Workbook(dataDir + "book1.xlsx");
// Convert the first table/list object (from the first worksheet) to normal range
wb.Worksheets[0].ListObjects[0].ConvertToRange();
// Save the file
wb.Save(dataDir + "output.xlsx");

オプションで範囲にテーブルを変換

Aspose.Cellsは、TableToRangeOptions クラスを介してテーブルを範囲に変換する際に追加のオプションを提供します。TableToRangeOptions クラスは、テーブル行の最後のインデックスを設定できる LastRow プロパティを提供します。指定した行インデックスまでテーブルの書式設定が保持され、その後の書式設定が削除されます。

以下のサンプルコードは、TableToRangeOptions クラスの使用例を示しています。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Open an existing file that contains a table/list object in it
Workbook workbook = new Workbook(dataDir + "book1.xlsx");
TableToRangeOptions options = new TableToRangeOptions();
options.LastRow = 5;
// Convert the first table/list object (from the first worksheet) to normal range
workbook.Worksheets[0].ListObjects[0].ConvertToRange(options);
// Save the file
workbook.Save(dataDir + "output.xlsx");