//3. check border consistency
//4. clear interior border of the merged cells
BorderStyle lstyle = fmt.getBorderLeft();
BorderStyle tstyle = fmt.getBorderTop();
BorderLineStyle lline = lstyle.getBorderLineStyle();
BorderLineStyle tline = tstyle.getBorderLineStyle();
BorderLineStyle rline = null;
BorderLineStyle bline = null;
String lcolor = lstyle.getBorderColor();
String tcolor = tstyle.getBorderColor();
String rcolor = null;
String bcolor = null;
boolean lequal = true;
boolean tequal = true;
boolean requal = true;
boolean bequal = true;
for (int row = top; row <= bottom; ++row) {
for (int col = left; col <= right; ++col) {
if (row == top && col == left) { //skip the first cell
continue;
}
final CellImpl x = (CellImpl) _matrix.getCellIndex(row, col).getCell();
x.mySetValue(null, false); //set content to null, but don't fire event
FormatImpl xfmt;
try {
xfmt = (FormatImpl) fmt.clone();
} catch (CloneNotSupportedException e) {
throw ModelException.Aide.wrap(e);
}
final FormatImpl ofmt = getFormatOrCreate(x);
//check top border
if (row == top) {
if (tequal) {
final BorderStyle tborder = ofmt.getBorderTop();
final BorderLineStyle tl = tborder.getBorderLineStyle();
final String tc = tborder.getBorderColor();
if (tline != tl) {
tequal = false;
}
if (!tcolor.equals(tc)) {
tequal = false;
}
if (tequal) {
xfmt.setBorderTop(tborder);
}
}
} else {
xfmt.setBorderTop(null);
}
//check bottom border
if (row == bottom) {
if (bequal) {
final BorderStyle bborder = ofmt.getBorderBottom();
final BorderLineStyle bl = bborder.getBorderLineStyle();
final String bc = bborder.getBorderColor();
if (bline == null) {
bline = bl;
} else if (bline != bl) {
bequal = false;
}
if (bcolor == null) {
bcolor = bc;
} else if (!bcolor.equals(bc)) {
bequal = false;
}
if (bequal) {
xfmt.setBorderBottom(bborder);
}
}
} else {
xfmt.setBorderBottom(null);
}
//check left border
if (col == left) {
if (lequal) {
final BorderStyle lborder = ofmt.getBorderLeft();
final BorderLineStyle ll = lborder.getBorderLineStyle();
final String lc = lborder.getBorderColor();
if (lline != ll) {
lequal = false;
}
if (!lcolor.equals(lc)) {
lequal = false;
}
if (lequal) {
xfmt.setBorderLeft(lborder);
}
}
} else {
xfmt.setBorderLeft(null);
}
//check right border
if (col == right) {
if (requal) {
final BorderStyle rborder = ofmt.getBorderRight();
final BorderLineStyle rl = rborder.getBorderLineStyle();
final String rc = rborder.getBorderColor();
if (rline == null) {
rline = rl;
} else if (rline != rl) {
requal = false;