行と列の表示と非表示
Contents
[
Hide
]
場合によっては、ワークシートの特定の行または列を非表示にして後で表示することが理にかなっていることがあります。 Microsoft Excel はこの機能を提供し、Aspose.Cells も同様です。
行と列の可視性の制御
Aspose.Cells はクラスを提供し、ワークブック、Microsoft Excel ファイルを表します。のワークブッククラスにはワークシート コレクションこれにより、開発者は Excel ファイル内の各ワークシートにアクセスできます。ワークシートは、ワークシートクラス。のワークシートクラスはCellsワークシート内のすべてのセルを表すコレクション。のCellsコレクションには、ワークシートの行または列を管理するためのメソッドがいくつか用意されています。これらのいくつかを以下で説明します。
行と列を非表示にする
開発者は、を呼び出して行または列を非表示にできます。行を非表示とHideColumnのメソッドCellsそれぞれコレクション。どちらのメソッドも、特定の行または列を非表示にするために、行と列のインデックスをパラメーターとして受け取ります。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Hiding the 3rd row of the worksheet | |
worksheet.Cells.HideRow(2); | |
// Hiding the 2nd column of the worksheet | |
worksheet.Cells.HideColumn(1); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.out.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
行の高さまたは列の幅をそれぞれ 0 に設定して、行または列を非表示にすることもできます。
行と列の表示
開発者は、非表示の行または列を表示するには、再表示行と列を非表示にしないのメソッドCellsそれぞれコレクション。どちらのメソッドも次の 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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Unhiding the 3rd row and setting its height to 13.5 | |
worksheet.Cells.UnhideRow(2, 13.5); | |
// Unhiding the 2nd column and setting its width to 8.5 | |
worksheet.Cells.UnhideColumn(1, 8.5); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
非表示の列を表示しているときに、以前に割り当てられた幅または元の幅に戻す必要がある場合は、負の幅の列を再表示してください。例: worksheet.Cells.UnhideColumn(5, -1)
複数の行と列を非表示にする
開発者は、複数の行または列を一度に非表示にするには、HideRowsとHideColumnsのメソッドCellsそれぞれコレクション。どちらのメソッドも、開始行または列のインデックスと、非表示にする行または列の数をパラメーターとして受け取ります。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Hiding 3,4 and 5 rows in the worksheet | |
worksheet.Cells.HideRows(2, 3); | |
// Hiding 2 and 3 columns in the worksheet | |
worksheet.Cells.HideColumns(1, 2); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "outputxls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |