行、列、およびスクロールバーを表示して非表示にする

行や列の表示と非表示

Aspose.Cellsには、Microsoft Excelファイルを表すWorkbookクラスが提供されています。WorkbookクラスにはWorksheetsコレクションが含まれ、Excelファイル内の各ワークシートにアクセスできるようになります。ワークシートはWorksheetクラスで表されます。Worksheetクラスにはワークシート内のすべてのセルを表すCellsコレクションがあります。Cellsコレクションには、ワークシート内の行や列を管理するためのいくつかのメソッドが提供されています。そのうちいくつかについて以下で説明します。

行と列を表示

開発者は、CellsコレクションのUnhideRowおよびUnhideColumnメソッドを呼び出すことで、非表示になっている任意の行または列を表示することができます。両方のメソッドは2つのパラメーターを取ります。

  • 行または列のインデックス - 特定の行または列を表示するために使用される行または列のインデックス。
  • 行の高さまたは列の幅 - 非表示にする行または列に割り当てられた行の高さまたは列の幅。
// 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();

行と列を非表示

開発者は、CellsコレクションのHideRowおよびHideColumnメソッドを呼び出すことで、特定の行または列を非表示にすることができます。両方のメソッドは、非表示にする特定の行または列のインデックスを取ります。

// 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();

複数の行と列を非表示

開発者は、CellsコレクションのHideRowsおよびHideColumnsメソッドを呼び出すことで、一度に複数の行または列を非表示にすることができます。両方のメソッドは、非表示にする開始行または列のインデックスと非表示にする行または列の数をパラメーターとして取ります。

// 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();

スクロールバーの表示と非表示

スクロールバーは、どのファイルの内容をナビゲートするために使用されます。通常、2種類のスクロールバーがあります。

  • 垂直スクロールバー
  • 水平スクロールバー

Microsoft Excelは、ユーザーがワークシートの内容をスクロールできるように、水平および垂直のスクロールバーを提供しています。Aspose.Cellsを使用すると、Excelファイルの両方のタイプのスクロールバーの表示/非表示を制御することができます。

スクロールバーの表示を制御する

Aspose.CellsはExcelファイルを表すWorkbookクラスを提供しています。WorkbookクラスにはExcelファイルを管理するためのさまざまなプロパティやメソッドが含まれています。スクロールバーの表示を制御するためには、WorkbookクラスのWorkbookSettings.IsVScrollBarVisibleメソッドやWorkbookSettings.IsHScrollBarVisibleプロパティを使用します。WorkbookSettings.IsVScrollBarVisibleWorkbookSettings.IsHScrollBarVisibleはBooleanプロパティであり、これらのプロパティにはtrueまたはfalseの値を格納できます。

スクロールバーを表示する

WorkbookクラスのWorkbookSettings.IsVScrollBarVisibleプロパティまたはWorkbookSettings.IsHScrollBarVisibleプロパティをtrueに設定することで、スクロールバーを表示します。

スクロールバーを非表示にする

WorkbookクラスのWorkbookSettings.IsVScrollBarVisibleプロパティまたはWorkbookSettings.IsHScrollBarVisibleプロパティをfalseに設定することで、スクロールバーを非表示にします。

サンプルコード

以下は、Excelファイルであるbook1.xlsを開き、両方のスクロールバーを非表示にし、変更されたファイルをoutput.xlsとして保存する完全なコードです。

// 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);
// Hiding the vertical scroll bar of the Excel file
workbook.Settings.IsVScrollBarVisible = false;
// Hiding the horizontal scroll bar of the Excel file
workbook.Settings.IsHScrollBarVisible = false;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();