Ottieni Max Range In Un Foglio di Lavoro

Come ottenere il range massimo

In Aspose.Cells for Python via .NET, se gli oggetti row e column sono inizializzati, queste righe e colonne verranno conteggiate fino all’area massima, anche se non ci sono dati nelle righe o colonne vuote.

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)

Come ottenere il range massimo dei dati

Nella maggior parte dei casi, abbiamo solo bisogno di ottenere tutti i range contenenti tutti i dati, anche se le celle vuote al di fuori del range sono formattate. E le impostazioni riguardanti forme, tabelle e tabelle pivot saranno ignorate.

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)

Come ottenere il range massimo di visualizzazione

Quando esportiamo tutti i dati dal foglio di lavoro in HTML, PDF o immagini, dobbiamo ottenere un’area che contenga tutti gli oggetti visibili, inclusi dati, stili, grafici, tabelle e tabelle pivot. I seguenti codici mostrano come renderizzare il range di visualizzazione massimo in 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)

Ecco il file excel di origine.