融合指定表格列
来源:互联网 发布:list 生成tree java 编辑:程序博客网 时间:2024/05/01 13:15
/** * 融合指定表格列 * @param table 融合的表格 * @param columnKey 融合参考列 * @param columnKeys 根据参考列需融合的列的集合 */ public static void mergeColumns(KDTable table,String columnKey,String[] columnKeys) { int beginIndex = 0; int endIndex = 0; KDTMergeManager merGeManager = table.getMergeManager(); for(int i=1;i<table.getRowCount();i++) { Object objBegin = table.getCell(beginIndex, columnKey).getValue(); Object objCurr = table.getCell(i, columnKey).getValue(); if(i<table.getRowCount()-1) { if(objCurr!=null && objBegin!=null && objCurr.toString().equals(objBegin.toString())) { continue; } endIndex = i-1; for(int j=0;j<columnKeys.length;j++) { merGeManager.mergeBlock(beginIndex, table.getColumnIndex(columnKeys[j]), endIndex, table.getColumnIndex(columnKeys[j])); } beginIndex = i; }else { if(objCurr!=null && objBegin!=null && objCurr.toString().equals(objBegin.toString())) { endIndex = i; }else { endIndex = i-1; } for(int j=0;j<columnKeys.length;j++) { merGeManager.mergeBlock(beginIndex, table.getColumnIndex(columnKeys[j]), endIndex, table.getColumnIndex(columnKeys[j])); } } } }