Fusione e Separazione Cells

Unire Cells in un foglio di lavoro.

Utilizzando Microsoft Excel

I seguenti passaggi descrivono come unire le celle nel foglio di lavoro utilizzando Microsoft Excel.

  1. Copia i dati desiderati nella cella in alto a sinistra all’interno dell’intervallo.
  2. Seleziona le celle che desideri unire.
  3. Per unire le celle in una riga o colonna e centrare il contenuto della cella, fare clic suUnisci e centra icona sulFormattazione barra degli strumenti.

Utilizzando Aspose.Cells

IlCells class ha alcuni metodi utili per l’attività. Ad esempio, il metodounire() unisce le celle in una singola cella all’interno di un intervallo di celle specificato.

Il seguente output viene generato dopo l’esecuzione del codice seguente.

Le celle (C6:E7) sono state unite

cose da fare:immagine_alt_testo

Esempio di codice

L’esempio seguente mostra come unire le celle (C6:E7) in un foglio di lavoro.

// 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.getSharedDataDir(MergingCellsInWorksheet.class) + "data/";
// Create a Workbook.
Workbook wbk = new Workbook();
// Create a Worksheet and get the first sheet.
Worksheet worksheet = wbk.getWorksheets().get(0);
// Create a Cells object to fetch all the cells.
Cells cells = worksheet.getCells();
// Merge some Cells (C6:E7) into a single C6 Cell.
cells.merge(5, 2, 2, 3);
// Input data into C6 Cell.
worksheet.getCells().get(5, 2).setValue("This is my value");
// Create a Style object to fetch the Style of C6 Cell.
Style style = worksheet.getCells().get(5, 2).getStyle();
// Create a Font object
Font font = style.getFont();
// Set the name.
font.setName("Times New Roman");
// Set the font size.
font.setSize(18);
// Set the font color
font.setColor(Color.getBlue());
// Bold the text
font.setBold(true);
// Make it italic
font.setItalic(true);
// Set the backgrond color of C6 Cell to Red
style.setForegroundColor(Color.getRed());
style.setPattern(BackgroundType.SOLID);
// Apply the Style to C6 Cell.
cells.get(5, 2).setStyle(style);
// Save the Workbook.
wbk.save(dataDir + "mergingcells_out.xls");
wbk.save(dataDir + "mergingcells_out.xlsx");
wbk.save(dataDir + "mergingcells_out.ods");
// Print message
System.out.println("Process completed successfully");

Unmerging (Splitting) Unificato Cells

Utilizzando Microsoft Excel

I seguenti passaggi descrivono come dividere le celle unite utilizzando Microsoft Excel.

  1. Seleziona la cella unita. Quando le celle sono state combinate,Unisci e centra è selezionato sulFormattazione barra degli strumenti.
  2. ClicUnisci e centra sulFormattazione barra degli strumenti.

Utilizzando Aspose.Cells

IlCells class ha un metodo chiamatoseparare() che divide le cellule nel loro stato originale. Il metodo separa le celle utilizzando il riferimento della cella nell’intervallo di celle unite.

Esempio di codice

L’esempio seguente mostra come dividere le celle unite (C6). L’esempio usa il file creato nell’esempio precedente e divide le celle unite.

// 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.getSharedDataDir(UnMergingCellsInWorksheet.class) + "data/";
// Create a Workbook.
Workbook wbk = new Workbook(dataDir + "mergingcells.xls");
// Create a Worksheet and get the first sheet.
Worksheet worksheet = wbk.getWorksheets().get(0);
// Create a Cells object to fetch all the cells.
Cells cells = worksheet.getCells();
// Unmerge the cells.
cells.unMerge(5, 2, 2, 3);
// Save the file.
wbk.save(dataDir + "UnMergingCellsInWorksheet_out.xls");
// Print message
System.out.println("Process completed successfully");

articoli Correlati