Ottieni Max Range In Un Foglio di Lavoro

Ottenere l’intervallo massimo

In Aspose.Cells, 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.

Workbook workbook = new Workbook("Book1.xlsx");
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
Worksheet sheet = worksheets[0];
//Gets the max data range.
int maxRow = sheet.Cells.MaxRow;
int maxColumn = sheet.Cells.MaxColumn;
//The range is A1:B3.
Range range = sheet.Cells.CreateRange(0, 0, maxRow + 1, maxColumn + 1);
sheet.Cells["A10"].PutValue(null);
maxRow = sheet.Cells.MaxRow;
maxColumn = sheet.Cells.MaxColumn;
//The range is udpated to A1:B10.
range = sheet.Cells.CreateRange(0, 0, maxRow + 1, maxColumn + 1);

Ottieni il massimo intervallo di 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.

// Instantiate a new Workbook.
Workbook workbook = new Workbook("Book1.xlsx");
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
Worksheet sheet = worksheets[0];
//Gets the max data range.
int maxRow = sheet.Cells.MaxDataRow;
int maxColumn = sheet.Cells.MaxDataColumn;
//The range is A1:B3.
Range range = sheet.Cells.CreateRange(0, 0, maxRow + 1, maxColumn + 1);
sheet.Cells["A10"].PutValue(null);
maxRow = sheet.Cells.MaxDataRow;
maxColumn = sheet.Cells.MaxDataColumn;
//The range is still A1:B3.
range = sheet.Cells.CreateRange(0, 0, maxRow + 1, maxColumn + 1);

Ottieni l’intervallo 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:

// Instantiate a new Workbook.
Workbook workbook = new Workbook("Book1.xlsx");
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
//Gets the max display range.
Range range = worksheets[0].Cells.MaxDisplayRange;
//Save the range to html
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.ExportActiveWorksheetOnly = true;
saveOptions.ExportArea = CellArea.CreateCellArea(range.FirstRow, range.FirstColumn, range.FirstRow + range.RowCount - 1, range.FirstColumn + range.ColumnCount - 1);
//Save the range.
workbook.Save("html.html", saveOptions);

Ecco il file excel di origine.