Excelのテーブルをデータの範囲に変換する
Microsoft Excelでテーブルを作成し、その機能を使用せずにテーブルのデータを保持したい場合があります。代わりに、テーブルのように見えるものが欲しい場合があります。フォーマットを失わずにテーブル内のデータを保持するには、テーブルを通常のデータの範囲に変換します。
Aspose.CellsはテーブルとリストオブジェクトのMicrosoft Excelのこの機能をサポートしています。
Microsoft Excel の使用
表をフォーマットを保持したまま範囲に素早く変換するには、範囲に変換 機能を使用します。Microsoft Excel 2007/2010では:
- 表内のどこかをクリックして、アクティブなセルが表の列内にあることを確認します。
- デザイン タブの ツール グループで、範囲に変換 をクリックします。
Aspose.Cellsの使用
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertTableToRange.class) + "tables/"; | |
// 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.getWorksheets().get(0).getListObjects().get(0).convertToRange(); | |
// Save the file | |
wb.save(dataDir + "ConvertTableToRange_out.xlsx"); |
オプションで範囲にテーブルを変換
Aspose.CellsはTableToRangeOptionsクラスを介してテーブルを範囲に変換する際に追加のオプションを提供します。TableToRangeOptionsクラスはLastRowプロパティを提供し、テーブル行の最後のインデックスを設定できます。指定された行インデックスまでテーブルの書式が保持され、その後の書式は削除されます。
以下のサンプルコードは、TableToRangeOptions クラスの使用例を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertTableToRangeWithOptions.class) + "Tables/"; | |
// Open an existing file that contains a table/list object in it | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
TableToRangeOptions options = new TableToRangeOptions(); | |
options.setLastRow(5); | |
// Convert the first table/list object (from the first worksheet) to normal range | |
workbook.getWorksheets().get(0).getListObjects().get(0).convertToRange(options); | |
// Save the file | |
workbook.save(dataDir + "ConvertTableToRangeWithOptions_out.xlsx"); |