//添加合计行
private void addSumRow(KDTable table){
// table.checkParsed();
if(table.getRowCount() == 0 || table.getRowCount() < 0){
return;
}
IRow firstRow = table.getRow(0);
if(firstRow.getCell("unitName").getValue() == null){
return;
}
Object tempAdmin = firstRow.getCell("unitName").getValue();
int total = 0;
int sum = 0;
int ctRecruitment = 0;
int sumCtRecruitment = 0;
int iRecruitment = 0;
int sumIRecruitment = 0;
int desfocRec = 0;
int sumDesfocRec = 0;
Object lastAdminOrg = null;
boolean flag = true;
for(int i = 0;i<table.getRowCount();i++){
IRow row = table.getRow(i);
if(row.getCell("unitName").getValue() == null
|| !row.getCell("unitName").getValue().equals(tempAdmin)){
IRow newRow = table.addRow(row.getRowIndex());
table.setRowCount(table.getRowCount() + 1);
newRow.getCell("unitName").setValue("小计");
newRow.getCell("unitName").getStyleAttributes().setHorizontalAlign(HorizontalAlignment.RIGHT);
newRow.getStyleAttributes().setBackground(Color.lightGray);
newRow.getStyleAttributes().setLocked(true);
lastAdminOrg = table.getRow(i - 1).getCell("area").getValue();
flag = true;
newRow.getCell("area").setValue(lastAdminOrg);
tempAdmin = row.getCell("unitName").getValue();
newRow.getCell("entrys.recNumber").setValue(new Integer(total));
sum += total;
total = 0;
}else{
lastAdminOrg = row.getCell("area").getValue();
if(row.getCell("entrys.recNumber").getValue() != null){
Integer tempTotal = (Integer) row.getCell("entrys.recNumber").getValue();
total += tempTotal.intValue();
}
}
}
IRow lastRow = table.addRow(table.getRowCount());
table.setRowCount(table.getRowCount() + 1);
lastRow.getCell("entrys.recNumber").setValue(new Integer(total));
lastRow.getCell("area").setValue(lastAdminOrg);
if(flag){
lastRow.getCell("area").setValue(table.getRow(table.getRowCount() - 1).getCell("area").getValue());
}
lastRow.getStyleAttributes().setBackground(Color.lightGray);
lastRow.getCell("unitName").setValue("小计");
lastRow.getCell("unitName").getStyleAttributes().setHorizontalAlign(HorizontalAlignment.RIGHT);
lastRow.getStyleAttributes().setLocked(true);
IRow totalRow = table.addRow(table.getRowCount());
table.setRowCount(table.getRowCount() + 1);
totalRow.getCell("entrys.recNumber").setValue(new Integer(sum+total));
totalRow.getStyleAttributes().setBackground(Color.cyan);
totalRow.getCell("unitName").setValue("合计");
totalRow.getStyleAttributes().setHorizontalAlign(HorizontalAlignment.RIGHT);
totalRow.getStyleAttributes().setLocked(true);
}
添加小计合计的数据行
最新推荐文章于 2022-12-15 09:12:53 发布