行と列の非表示および表示
Contents
[
Hide
]
紹介
時には、ユーザーがワークシートの特定の行または列を非表示にし、後で表示する必要がある場合があります。Microsoft Excelではこの機能を提供しており、Aspose.Cellsも同様です。
行と列の表示を制御する
Aspose.Cellsは、Microsoft Excelファイルを表すWorkbookクラスを提供します。Workbook クラスには、Excelファイル内の各ワークシートへのアクセスを可能にするWorksheetCollection が含まれています。ワークシートはWorksheet クラスによって表されます。Worksheet クラスは、ワークシート内のすべてのセルを表すCells コレクションを提供します。Cells コレクションには、ワークシート内の行または列を管理するためのいくつかのメソッドが提供されています。以下ではそのうちのいくつかを説明します。
行または列の非表示
開発者は、Cells コレクションのHideRow およびHideColumn メソッドを呼び出すことで、行または列を非表示にすることができます。それぞれのメソッドは、非表示にする特定の行または列のインデックスをパラメータとして取ります。
注: 行または列を非表示にすることは、行の高さまたは列の幅をそれぞれ0に設定することで可能です。
This file contains 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-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."); |
行と列の表示
開発者は、Cells コレクションのUnhideRow およびUnhideColumn メソッドを呼び出すことで、非表示になっている行または列を元に戻すことができます。それぞれのメソッドは2つのパラメータを取ります:
- 行または列のインデックス - 特定の行または列を表示するために使用される行または列のインデックス。
- 行の高さまたは列の幅 - 表示された後の行の高さまたは列の幅。すると行または列はその後元の幅または高さに戻ります。
This file contains 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-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."); |
非表示の行/列を表示する際、以前に割り当てられた幅または高さ、または元の幅または高さに復元する必要がある場合は、負の幅または高さで行または列を非表示にした後、その行または列を再表示してください。例: worksheet.getCells().unhideColumn(5, -1)