private static ChangeInfo merge0(Worksheet sheet, int tRow, int lCol, int bRow, int rCol) {
final List<MergeChange> changes = new ArrayList<MergeChange>();
final Set<Ref> all = new HashSet<Ref>();
final Set<Ref> last = new HashSet<Ref>();
//find the left most non-blank cell.
Cell target = null;
for(int r = tRow; target == null && r <= bRow; ++r) {
for(int c = lCol; c <= rCol; ++c) {
final Cell cell = BookHelper.getCell(sheet, r, c);
if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
target = cell;
break;
}
}
}
CellStyle style = null;
if (target != null) { //found the target
final int tgtRow = target.getRowIndex();
final int tgtCol = target.getColumnIndex();
final int nRow = tRow - tgtRow;
final int nCol = lCol - tgtCol;
if (nRow != 0 || nCol != 0) { //if target not the left-top one, move to left-top
final ChangeInfo info = BookHelper.moveRange(sheet, tgtRow, tgtCol, tgtRow, tgtCol, nRow, nCol);
if (info != null) {
changes.addAll(info.getMergeChanges());
last.addAll(info.getToEval());
all.addAll(info.getAffected());
}
}
final CellStyle source = target.getCellStyle();
style = source.getIndex() == 0 ? null : sheet.getWorkbook().createCellStyle();
if (style != null) {
style.cloneStyleFrom(source);
style.setBorderLeft(CellStyle.BORDER_NONE);
style.setBorderTop(CellStyle.BORDER_NONE);
style.setBorderRight(CellStyle.BORDER_NONE);
style.setBorderBottom(CellStyle.BORDER_NONE);
target.setCellStyle(style); //set all cell in the merged range to CellStyle of the target minus border
}
//1st row (exclude 1st cell)
for (int c = lCol + 1; c <= rCol; ++c) {
final Cell cell = getOrCreateCell(sheet, tRow, c);
cell.setCellStyle(style); //set all cell in the merged range to CellStyle of the target minus border
final Set<Ref>[] refs = BookHelper.setCellValue(cell, (RichTextString) null);
if (refs != null) {
last.addAll(refs[0]);
all.addAll(refs[1]);
}
}
//2nd row and after
for(int r = tRow+1; r <= bRow; ++r) {
for(int c = lCol; c <= rCol; ++c) {
final Cell cell = getOrCreateCell(sheet, r, c);
cell.setCellStyle(style); //set all cell in the merged range to CellStyle of the target minus border
final Set<Ref>[] refs = BookHelper.setCellValue(cell, (RichTextString) null);
if (refs != null) {
last.addAll(refs[0]);
all.addAll(refs[1]);
}