Çalışma sayfasında birleştirilmiş hücreleri tespit et
Bu makale, çalışma sayfasındaki birleştirilmiş hücre alanlarını nasıl alacağınız hakkında bilgi sağlar.
Aspose.Cells, çalışma sayfasındaki birleştirilmiş hücre alanlarını almanıza izin verir. Onları ayırabilir (bölünebilir)siniz. Bu makale, görevi gerçekleştirmek için Aspose.Cells API’sını kullanarak en basit kodu gösterir.
Bileşen, tüm birleştirilmiş hücreleri alabilen bir Cells.GetMergedAreas() yöntemi sağlar. Aşağıdaki kod örneği, bir çalışma sayfasındaki birleştirilmiş hücreleri nasıl tespit edeceğinizi gösterir.
// 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); | |
// Instantiate a new Workbook | |
// Open an existing excel file | |
Workbook wkBook = new Workbook(dataDir + "SampleInput.xlsx"); | |
// Get a worksheet in the workbook | |
Worksheet wkSheet = wkBook.Worksheets["Sheet2"]; | |
// Clear its contents | |
wkSheet.Cells.Clear(); | |
// Get merged areas | |
CellArea[] areas = wkSheet.Cells.GetMergedAreas(); | |
// Define some variables | |
int frow, fcol, erow, ecol, trows, tcols; | |
// Loop through the arraylist and get each cellarea | |
// To unmerge it | |
for (int i = 0; i < areas.Length; i++) | |
{ | |
frow = areas[i].StartRow; | |
fcol = areas[i].StartColumn; | |
erow = areas[i].EndRow; | |
ecol = areas[i].EndColumn; | |
trows = erow - frow + 1; | |
tcols = ecol - fcol + 1; | |
wkSheet.Cells.UnMerge(frow, fcol, trows, tcols); | |
} | |
dataDir = dataDir + "MergeTrial.out.xlsx"; | |
// Save the excel file | |
wkBook.Save(dataDir); |