Hücreleri Birleştirme ve Ayırma
Giriş
Her zaman her satır veya sütunda aynı hücre sayısını istemezsiniz. Örneğin, birkaç sütunu kapsayan bir hücreye başlık koymak isteyebilirsiniz. Veya, bir fatura oluştururken toplam için daha az sütun isteyebilirsiniz. İki veya daha fazla hücreden bir hücre yapmak için hücreleri birleştirin. Microsoft Excel, kullanıcılara dosyaları seçme ve istedikleri şekilde elektronik tabloyu yapılandırmak için birleştirmelerine izin verir.
Çalışsheet’te Hücreleri Birleştirme
Microsoft Excel’de Hücreleri Birleştirme
Aşağıdaki adımlar, MS Excel kullanarak çalışsheet’te hücreleri birleştirmeyi açıklar.
- İstenen veriyi aralıktaki en sol üst hücreye kopyalayın.
- Birleştirmek istediğiniz hücreleri seçin.
- 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 ile Hücreleri Birleştirmek
Aspose.Cells.Cells Sınıfı, görev için bazı kullanışlı yöntemlere sahiptir. Örneğin, Merge() yöntemi belirtilen aralıkta hücreleri tek bir hücrede birleştirir.
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Create a Workbook. | |
Workbook wbk = new Workbook(); | |
// Create a Worksheet and get the first sheet. | |
Worksheet worksheet = wbk.Worksheets[0]; | |
// Create a Cells object ot fetch all the cells. | |
Cells cells = worksheet.Cells; | |
// Merge some Cells (C6:E7) into a single C6 Cell. | |
cells.Merge(5, 2, 2, 3); | |
// Input data into C6 Cell. | |
worksheet.Cells[5, 2].PutValue("This is my value"); | |
// Create a Style object to fetch the Style of C6 Cell. | |
Style style = worksheet.Cells[5, 2].GetStyle(); | |
// Create a Font object | |
Font font = style.Font; | |
// Set the name. | |
font.Name = "Times New Roman"; | |
// Set the font size. | |
font.Size = 18; | |
// Set the font color | |
font.Color = System.Drawing.Color.Blue; | |
// Bold the text | |
font.IsBold = true; | |
// Make it italic | |
font.IsItalic = true; | |
// Set the backgrond color of C6 Cell to Red | |
style.ForegroundColor = System.Drawing.Color.Red; | |
style.Pattern = BackgroundType.Solid; | |
// Apply the Style to C6 Cell. | |
cells[5, 2].SetStyle(style); | |
// Save the Workbook. | |
wbk.Save(dataDir + "mergingcells.out.xls"); |
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.
- Birleştirilmiş hücreyi seçin. Hücreler birleştirildiğinde, Birleştir ve Ortala, Biçimlendirme araç çubuğunda seçilidir.
- Biçimlendirme araç çubuğunda Birleştir ve Ortala‘ya tıklayın.
Aspose.Cells Kullanımı
Aspose.Cells.Cells sınıfının UnMerge() adında bir yöntemi vardır; bu yöntem, hücreleri birleştirdiği hücre referansını kullanarak ayırır.
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a Workbook. | |
// Open the excel file. | |
Workbook wbk = new Aspose.Cells.Workbook(dataDir + "mergingcells.xls"); | |
// Create a Worksheet and get the first sheet. | |
Worksheet worksheet = wbk.Worksheets[0]; | |
// Create a Cells object ot fetch all the cells. | |
Cells cells = worksheet.Cells; | |
// Unmerge the cells. | |
cells.UnMerge(5, 2, 2, 3); | |
// Save the file. | |
wbk.Save(dataDir + "unmergingcells.out.xls"); |