ワークシートとタブの表示と非表示

ワークシートの表示と非表示

Excelファイルには1つ以上のワークシートが含まれることがあります。Excelファイルを作成するときには、作業するExcelファイルにワークシートを追加します。Excelファイル内の各ワークシートは、独自のデータや書式設定などを持つため、他のワークシートから独立しています。開発者は時々、Excelファイル内で特定のワークシートを非表示にし、他のワークシートを表示したい場合があります。そのため、Aspose.Cellsは開発者がExcelファイル内のワークシートの表示を制御することを可能にします。

Aspose.CellsはExcelファイルを表すWorkbookクラスを提供します。WorkbookクラスにはWorksheetsコレクションが含まれており、Excelファイル内の各ワークシートにアクセスできます。

ワークシートはWorksheetクラスによって表されます。Worksheetクラスにはワークシートを管理するための多くのプロパティやメソッドが提供されています。ワークシートの表示を制御するには、IsVisibleクラスのWorksheetプロパティを使用します。IsVisibleはBooleanプロパティであり、trueまたはfalseの値のみを格納できます。

ワークシートを表示する

ワークシートをtrueに設定することで、ワークシートを表示します。

ワークシートを非表示にする

ワークシートをfalseに設定することで、ワークシートを非表示にします。

// 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 with 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 first worksheet of the Excel file
worksheet.IsVisible = false;
// Shows first worksheet of the Excel file
//Worksheet.IsVisible = true;
// Saving the modified Excel file in default (that is Excel 2003) format
workbook.Save(dataDir + "output.out.xls");
// Closing the file stream to free all resources
fstream.Close();

タブの表示と非表示

Microsoft Excelの下部をよく見ると、いくつかのコントロールが表示されます。これには次のものが含まれます:

  • シートタブ。
  • タブのスクロールボタン。

シートタブはExcelファイル内のワークシートを表します。任意のタブをクリックするとそのワークシートに切り替えることができます。ワークブック内にワークシートが多いほど、シートタブも多く表示されます。Excelファイルに多くのワークシートが含まれている場合は、それらをナビゲートするためのボタンが必要になります。そのため、Microsoft Excelはシートタブのスクロールボタンを提供しています。

Aspose.Cellsを使用すると、開発者はExcelファイル内のシートタブとタブのスクロールボタンの表示を制御できます。

Aspose.CellsはExcelファイルを表すWorkbookクラスを提供します。WorkbookクラスにはExcelファイルを管理するための多くのプロパティやメソッドが提供されています。Excelファイル内のタブの表示を制御するために、開発者はWorkbookクラスのWorkbookSettings.ShowTabsプロパティを使用できます。WorkbookSettings.ShowTabsはBooleanプロパティであり、trueまたはfalseの値のみを格納できます。

タブを表示する

trueに設定することで、タブを表示します。

タブを非表示にする

falseに設定することで、Excelファイル内のタブを非表示にします。

以下は、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);
// Opening the Excel file
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Hiding the tabs of the Excel file
workbook.Settings.ShowTabs = false;
// Shows the tabs of the Excel file
//workbook.Settings.ShowTabs = true;
// Saving the modified Excel file
workbook.Save(dataDir + "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);
// Instantiating a Workbook object
// Opening the Excel file
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Hiding the tabs of the Excel file
workbook.Settings.ShowTabs = true;
// Adjusting the sheet tab bar width
workbook.Settings.SheetTabBarWidth = 800;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");