行と列の表示と非表示
序章
場合によっては、ワークシートの特定の行または列を非表示にして後で表示する必要がある場合もあります。 Microsoft Excel はこの機能を提供し、Aspose.Cells と同様です。
行と列の可視性の制御
Aspose.Cells はクラスを提供し、ワークブック、Microsoft Excel ファイルを表します。のワークブッククラスにはワークシート コレクションこれにより、Excel ファイル内の各ワークシートにアクセスできます。ワークシートは、ワークシートクラス。のワークシートクラスはCellsワークシート内のすべてのセルを表すコレクション。のCellsコレクションには、ワークシートの行または列を管理するためのメソッドがいくつか用意されています。これらのいくつかを以下で説明します。
行または列を非表示にする
開発者は、を呼び出して行または列を非表示にできます。[行を非表示](https://reference.aspose.com/cells/java/com.aspose.cells/cells#hideRow(int) ) と[HideColumn](https://reference.aspose.com/cells/java/com.aspose.cells/cells#hideColumn(int) のメソッド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(HidingRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Hiding the 3rd row of the worksheet | |
cells.hideRow(2); | |
// Hiding the 2nd column of the worksheet | |
cells.hideColumn(1); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "HidingRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns hidden successfully."); |
行と列の表示
開発者は、非表示の行または列を再表示できます。[再表示行](https://reference.aspose.com/cells/java/com.aspose.cells/cells#unhideRow(int,%20double) ) と[列を非表示にしない](https://reference.aspose.com/cells/java/com.aspose.cells/cells#unhideColumn(int,%20double) のメソッドCellsそれぞれコレクション。どちらのメソッドも次の 2 つのパラメーターを取ります。
- 行または列のインデックス 特定の行または列を表示するために使用される行または列のインデックス。
- 行の高さまたは列の幅 行または列が表示された後に割り当てられる行の高さまたは列の幅。
// 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(UnhidingRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Unhiding the 3rd row and setting its height to 13.5 | |
cells.unhideRow(2, 13.5); | |
// Unhiding the 2nd column and setting its width to 8.5 | |
cells.unhideColumn(1, 8.5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "UnhidingRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns unhidden successfully."); |