Obtener el rango máximo en una hoja de cálculo

Cómo obtener el rango máximo

En Aspose.Cells para Python via .NET, si los objetos row y column están inicializados, se contarán las filas y columnas para formar la área máxima, incluso si no hay datos en las filas o columnas vacías.

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)

Cómo obtener el rango máximo de datos

En la mayoría de los casos, solo necesitamos obtener todos los rangos que contienen todos los datos, incluso si las celdas vacías fuera del rango están formateadas. Y los ajustes sobre formas, tablas y tablas dinámicas se ignorarán.

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)

Cómo obtener el rango máximo de visualización

Cuando exportamos todos los datos de la hoja de cálculo a HTML, PDF o imágenes, necesitamos obtener un área que contenga todos los objetos visibles, incluidos los datos, estilos, gráficos, tablas y tablas dinámicas. Los siguientes códigos muestran cómo renderizar el rango de visualización máxima a 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)

Aquí está el archivo de excel fuente.