Hücreleri Birleştirme ve Ayırma

Bir Çalışma Sayfasında Hücreleri Birleştirme.

Microsoft Excel Kullanımı

Aşağıdaki adımlar, Microsoft Excel kullanarak çalışma sayfasındaki hücreleri nasıl birleştireceğinizi açıklar.

  1. İstenen veriyi aralıktaki en sol üst hücreye kopyalayın.
  2. Birleştirmek istediğiniz hücreleri seçin.
  3. Bir satır veya sütunda hücreleri birleştirmek ve hücre içeriğini ortalamak için, Biçimlendirme araç çubuğundaki Birleştir ve Ortala simgesine tıklayın.

Aspose.Cells Kullanımı

Cells sınıfı, görev için bazı yararlı yöntemlere sahiptir. Örneğin, merge() yöntemi, hücreleri belirtilen hücre aralığı içinde tek bir hücreye birleştirir.

Aşağıdaki çıktı, aşağıdaki kodun çalıştırılmasından sonra oluşturulur.

Hücreler (C6:E7) birleştirildi

todo:image_alt_text

Kod Örneği

Aşağıdaki örnek, bir çalışsheet’te (C6:E7) hücrelerin nasıl birleştirileceğini göstermektedir.

// 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");

Hücreleri Ayırma (Birleştirmeyi Bölmek)

Microsoft Excel Kullanımı

Aşağıdaki adımlar, Microsoft Excel kullanarak birleştirilmiş hücreleri nasıl ayıracağınızı açıklar.

  1. Birleştirilmiş hücreyi seçin. Hücreler birleştirildiğinde, Birleştir ve Ortala, Biçimlendirme araç çubuğunda seçilidir.
  2. Biçimlendirme araç çubuğunda Birleştir ve Ortala‘ya tıklayın.

Aspose.Cells Kullanımı

Cells sınıfı, unMerge() adlı bir yönteme sahiptir. Bu yöntem, hücreleri birleştirilmiş hücre aralığındaki hücre başvurusunu kullanarak ayrıştırır.

Kod Örneği

Aşağıdaki örnek, birleştirilmiş hücreleri (C6) nasıl ayıracağınızı göstermektedir. Örnek, önceki örnekte oluşturulan dosyayı kullanır ve birleştirilmiş hücreleri ayırır.

// 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");

İlgili Makaleler