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

行や列の表示と非表示

Aspose.Cells for Python via .NETは、Workbookクラスを提供します。Workbookクラスは、Excelファイル内の各ワークシートにアクセスできるworksheetsコレクションを含みます。Worksheetクラスは、すべてのセルを表すWorksheetコレクションを提供します。cellsコレクションは、行や列を管理するいくつかのメソッドを提供します。

行と列を表示

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

  • 行または列のインデックス - 特定の行または列を表示するために使用される行または列のインデックス。
  • 行の高さまたは列の幅 - 非表示にする行または列に割り当てられた行の高さまたは列の幅。
from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Unhiding the 3rd row and setting its height to 13.5
worksheet.cells.unhide_row(2, 13.5)
# Unhiding the 2nd column and setting its width to 8.5
worksheet.cells.unhide_column(1, 8.5)
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")
# Closing the file stream to free all resources
fstream.close()

行と列を非表示

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

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Hiding the 3rd row of the worksheet
worksheet.cells.hide_row(2)
# Hiding the 2nd column of the worksheet
worksheet.cells.hide_column(1)
# Saving the modified Excel file
workbook.save(dataDir + "output.out.xls")
# Closing the file stream to free all resources
fstream.close()

複数の行と列を非表示

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

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Hiding 3,4 and 5 rows in the worksheet
worksheet.cells.hide_rows(2, 3)
# Hiding 2 and 3 columns in the worksheet
worksheet.cells.hide_columns(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 for Python via .NETを使用して、Excelファイルの両タイプのスクロールバーの表示/非表示を制御できます。

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

Aspose.Cells for Python via .NETは、Workbookクラスを提供します。Workbookクラスは、Excelファイルの管理に幅広いプロパティとメソッドを含みます。スクロールバーの表示を制御するには、 WorkbookクラスのWorkbookSettings.is_v_scroll_bar_visibleWorkbookSettings.is_h_scroll_bar_visibleプロパティを使用します。WorkbookSettings.is_v_scroll_bar_visibleWorkbookSettings.is_h_scroll_bar_visibleは真偽値のプロパティであり、これらのプロパティにはtrueまたはfalseの値のみを格納できます。

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

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

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

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

サンプルコード

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

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Hiding the vertical scroll bar of the Excel file
workbook.settings.is_v_scroll_bar_visible = False
# Hiding the horizontal scroll bar of the Excel file
workbook.settings.is_h_scroll_bar_visible = False
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")
# Closing the file stream to free all resources
fstream.close()