Mostra e Nascondi Righe Colonne e Barre di Scorrimento

Mostra e nascondi righe e colonne

Aspose.Cells per Python via .NET fornisce una classe, Workbook, che rappresenta un file Microsoft Excel. La classe Workbook contiene una collezione worksheets che permette agli sviluppatori di accedere a ogni foglio di lavoro nel file Excel. Un foglio di lavoro è rappresentato dalla classe Worksheet. La classe Worksheet contiene una collezione cells che rappresenta tutte le celle nel foglio di lavoro. La collezione Cells fornisce diversi metodi per gestire righe o colonne in un foglio di lavoro. Alcuni di questi sono illustrati di seguito.

Mostra Righe e Colonne

Gli sviluppatori possono mostrare qualsiasi riga o colonna nascosta chiamando rispettivamente i metodi unhide_row e unhide_column della collezione Cells. Entrambi i metodi prendono due parametri:

  • Indice della riga o colonna - l’indice di una riga o colonna che viene utilizzato per mostrare la riga o colonna specifica.
  • Altezza della riga o larghezza della colonna - l’altezza della riga o la larghezza della colonna assegnata alla riga o colonna dopo l’annullamento della visualizzazione.
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()

Nascondi Righe e Colonne

Gli sviluppatori possono nascondere una riga o colonna chiamando rispettivamente i metodi hide_row e hide_column della collezione Cells. Entrambi i metodi prendono l’indice della riga e della colonna come parametro per nascondere la riga o colonna specifica.

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

Nascondi Più Righe e Colonne

Gli sviluppatori possono nascondere più righe o colonne contemporaneamente chiamando rispettivamente i metodi hide_rows e hide_columns della collezione Cells. Entrambi i metodi prendono l’indice di partenza della riga o colonna e il numero di righe o colonne che devono essere nascoste come parametri.

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

Mostra e nascondi le barre di scorrimento

Le barre di scorrimento vengono utilizzate per navigare nei contenuti di qualsiasi file. Normalmente, ci sono due tipi di barre di scorrimento:

  • Barre di scorrimento verticali
  • Barre di scorrimento orizzontali

Microsoft Excel offre anche barre di scorrimento orizzontali e verticali in modo che gli utenti possano scorrere i contenuti del foglio di lavoro. Usando Aspose.Cells per Python via .NET, gli sviluppatori possono controllare la visibilità di entrambi i tipi di barre di scorrimento nei file Excel.

Controllare la visibilità delle barre di scorrimento

Aspose.Cells per Python via .NET fornisce una classe, Workbook, che rappresenta un file Excel. La classe Workbook offre molte proprietà e metodi per gestire un file Excel. Per controllare la visibilità delle barre di scorrimento, usa le proprietà Workbook e WorkbookSettings.is_v_scroll_bar_visible della classe. WorkbookSettings.is_h_scroll_bar_visible e WorkbookSettings.is_v_scroll_bar_visible sono proprietà Booleane, il che significa che queste proprietà possono memorizzare solo valori true o false.

Rendere visibili le barre di scorrimento

Rendere le barre di scorrimento visibili impostando la proprietà WorkbookSettings.is_v_scroll_bar_visible o WorkbookSettings.is_h_scroll_bar_visible della classe Workbook su true.

Nascondere le barre di scorrimento

Nascondere le barre di scorrimento impostando la proprietà WorkbookSettings.is_v_scroll_bar_visible o WorkbookSettings.is_h_scroll_bar_visible della classe Workbook su false.

Codice di Esempio

Di seguito è riportato un codice completo che apre un file Excel, book1.xls, nasconde entrambe le barre di scorrimento e quindi salva il file modificato come 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()