使用 Aspose.Cells 检测合并的 Cells

Aspose.Cells - 检测合并 Cells

在 Microsoft Excel 中,可以将多个单元格合并为一个。这通常用于创建复杂的表格,或创建一个包含跨多个列的标题的单元格。 Aspose.Cells 允许您识别工作表中的合并单元格区域。您也可以取消合并它们。

Java

 //Get the merged cells list to put it into the arraylist object

ArrayList<CellArea> al = worksheet.getCells().getMergedCells();

//Define cellarea

CellArea ca;

//Define some variables

int frow, fcol, erow, ecol;

// Print Message

System.out.println("Merged Areas: \n"+ al.toString());

//Loop through the arraylist and get each cellarea to unmerge it

for(int i = al.size()-1 ; i > -1; i--)

{

	ca = new CellArea();

	ca = (CellArea)al.get(i);

	frow = ca.StartRow;

	fcol = ca.StartColumn;

	erow = ca.EndRow;

	ecol = ca.EndColumn;

	System.out.println((i+1) + ". [" + fcol +"," + frow +"] " + "[" + ecol +"," + erow +"]");

	worksheet.getCells().unMerge(frow, fcol, erow, ecol);

}

下载运行代码

下载示例代码