public class ExcelCell {
public static boolean isMergedRegion(HSSFSheet sheet,int row ,int column)
{
int sheetMergeCount = sheet.getNumMergedRegions();
for (int i = 0; i < sheetMergeCount; i++) {
Region ca = sheet.getMergedRegionAt(i);
int firstColumn = ca.getColumnFrom();
int lastColumn = ca.getColumnTo();
int firstRow = ca.getRowFrom();
int lastRow = ca.getRowTo();
if(row >= firstRow && row <= lastRow)
{
if(column >= firstColumn && column <= lastColumn)
{
return true;
}
}
}
return false;
}
}
===============================================
rowNum = sheet.getPhysicalNumberOfRows();
for (int i = 7; i < rowNum; i++) {
row = sheet.getRow(i);
if(ExcelCell.isMergedRegion(sheet, row.getRowNum(), 1)){
System.out.println("合并单元格,停止循环");
break;
}
try {
//获取单元格对象
System.out.println(i+" "+row.getCell(0)+"==>"+row.getCell(0).getCellStyle().getIndention()+" ****"+row.getCell(1)+" "+row.getCell(2));
} catch (Exception e) {
e.printStackTrace();
}
}