Rilevare celle unite in un foglio di lavoro

Dimostrazione

Questo esempio utilizza un file modello di Microsoft Excel chiamato MergeTrial. Ha alcune aree di celle unite in un foglio chiamato Merge Trial.

Il file di modello

todo:image_alt_text

Aspose.Cells fornisce il metodo Cells.getMergedCells() che viene utilizzato per ottenere tutte le celle unite.

Quando viene eseguito il codice seguente, cancella i contenuti del foglio e separa tutte le aree delle celle prima di salvare nuovamente il file.

Il file di output

todo:image_alt_text

Esempio di codice

Si prega di vedere il seguente codice di esempio per scoprire come identificare le aree di celle unite in un foglio di lavoro e separarle.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetectMergedCells.class);
// Instantiate a new Workbook
Workbook wkBook = new Workbook(dataDir + "MergeTrial.xls");
// Get a worksheet in the workbook
Worksheet wkSheet = wkBook.getWorksheets().get("Merge Trial");
// Clear its contents
wkSheet.getCells().clearContents(0, 0, wkSheet.getCells().getMaxDataRow(),
wkSheet.getCells().getMaxDataColumn());
// Get all merged cell aeras
CellArea[] areas = wkSheet.getCells().getMergedAreas();
// Define some variables
int frow, fcol, erow, ecol;
// Loop through the arraylist and get each cellarea to unmerge it
for (int i = areas.length - 1; i > -1; i--)
{
frow = areas[i].StartRow;
fcol = areas[i].StartColumn;
erow = areas[i].EndRow;
ecol = areas[i].EndColumn;
wkSheet.getCells().unMerge(frow, fcol, erow, ecol);
}
// Save the excel file
wkBook.save(dataDir + "output_MergeTrial.xls");

Articoli Correlati