Obtenir la plage maximale dans une feuille de calcul

Comment obtenir la plage maximale

Dans Aspose.Cells pour Python via .NET, si les objets row et column sont initialisés, ces lignes et colonnes seront comptées dans la zone maximale, même s’il n’y a pas de données dans les lignes ou colonnes vides.

from aspose.cells import Workbook
workbook = Workbook("Book1.xlsx")
# Get all the worksheets in the book.
worksheets = workbook.worksheets
sheet = worksheets[0]
# Gets the max data range.
maxRow = sheet.cells.max_row
maxColumn = sheet.cells.max_column
# The range is A1:B3.
range = sheet.cells.create_range(0, 0, maxRow + 1, maxColumn + 1)
sheet.cells.get("A10").put_value(None)
maxRow = sheet.cells.max_row
maxColumn = sheet.cells.max_column
# The range is udpated to A1:B10.
range = sheet.cells.create_range(0, 0, maxRow + 1, maxColumn + 1)

Comment obtenir la plage de données maximale

Dans la plupart des cas, nous n’avons besoin d’obtenir que toutes les plages contenant toutes les données, même si les cellules vides en dehors de la plage sont formatées. Et les paramètres concernant les formes, tableaux et tableaux croisés dynamiques seront ignorés.

from aspose.cells import Workbook
# Instantiate a new Workbook.
workbook = Workbook("Book1.xlsx")
# Get all the worksheets in the book.
worksheets = workbook.worksheets
sheet = worksheets[0]
# Gets the max data range.
maxRow = sheet.cells.max_data_row
maxColumn = sheet.cells.max_data_column
# The range is A1:B3.
range = sheet.cells.create_range(0, 0, maxRow + 1, maxColumn + 1)
sheet.cells.get("A10").put_value(None)
maxRow = sheet.cells.max_data_row
maxColumn = sheet.cells.max_data_column
# The range is still A1:B3.
range = sheet.cells.create_range(0, 0, maxRow + 1, maxColumn + 1)

Comment obtenir la plage d’affichage maximale

Lorsque nous exportons toutes les données de la feuille de calcul vers HTML, PDF ou images, nous devons obtenir une zone contenant tous les objets visibles, y compris les données, les styles, les graphiques, les tableaux et les tableaux croisés dynamiques. Les codes suivants montrent comment rendre la plage d’affichage maximale en html :

from aspose.cells import CellArea, HtmlSaveOptions, Workbook
# Instantiate a new Workbook.
workbook = Workbook("Book1.xlsx")
# Get all the worksheets in the book.
worksheets = workbook.worksheets
# Gets the max display range.
range = worksheets[0].cells.max_display_range
# Save the range to html
saveOptions = HtmlSaveOptions()
saveOptions.export_active_worksheet_only = True
saveOptions.export_area = CellArea.create_cell_area(range.first_row, range.first_column, range.first_row + range.row_count - 1, range.first_column + range.column_count - 1)
# Save the range.
workbook.save("html.html", saveOptions)

Voici le fichier excel source.