EAS BOS 报表添加合计行,和每行合计

来源:互联网 发布:qstring转char数组 编辑:程序博客网 时间:2024/05/17 10:54

/**

* 添加报表合计行

* @param table 

* @param fieldSumList 需要合计列

*/

public static void appendFootRow(KDTable table, List fieldSumList) {


Map columnMap = new HashMap();

columnMap.clear();

KDTable tableSum = table;

for (int j = 0; j < fieldSumList.size(); ++j) {

String Number = (String) fieldSumList.get(j);

if (Number != null) {

BigDecimal dbSum = new BigDecimal("0");

for (int r = 0; r < tableSum.getRowCount(); ++r) {

if (tableSum.getRow(r).getStyleAttributes().isHided()) {

continue;

}


ICell cell = tableSum.getRow(r).getCell(Number);


String cellValue = tableSum.getCellDisplayText(cell);

if (cellValue != null) {

cellValue = cellValue.toString().replaceAll(",", "");

}

if (!StringUtility.isNumber(cellValue)) {

Object cellObj = cell.getValue();

if (cellObj != null)

cellValue = cellObj.toString();

if (!StringUtility.isNumber(cellValue)) {

continue;

}

}


BigDecimal bigdem = new BigDecimal(String

.valueOf(cellValue).trim());

dbSum = dbSum.add(bigdem);

}


String strSum = dbSum.toString();

columnMap.put(Number, strSum);

}

}

if (columnMap.size() > 0) {

IRow footRow = tableSum.addRow();


String colFormat = "%{#,###.##########}f";


String total = EASResource

.getString("com.kingdee.eas.framework.FrameWorkResource.Msg_Total");

tableSum.getIndexColumn().setWidthAdjustMode((short) 1);

tableSum.getIndexColumn().setWidth(30);

footRow.getCell(0).setValue(total);

footRow.getStyleAttributes()

.setBackground(new Color(246, 246, 191));

footRow.getStyleAttributes().setNumberFormat(colFormat);

footRow.getStyleAttributes().setHorizontalAlign(

Styles.HorizontalAlignment.getAlignment("right"));

footRow.getStyleAttributes().setFontColor(Color.BLACK);


Iterator valueIterator = columnMap.entrySet().iterator();

while (valueIterator.hasNext()) {

Map.Entry colEntry = (Map.Entry) valueIterator.next();

String colIndex = (String) colEntry.getKey();

String colValue = (String) colEntry.getValue();

footRow.getCell(colIndex).setValue(colValue);

}


}

}


----------------------------------------------------------------------------------------------

//这里合计所有以"F"打头列名行,如果需要指定合计列只需要添加列参数即可,需求预先添加合计列:Total

public static void appendTotal(KDTable table)

{

Map columnMap = new HashMap();

int rowCount = table.getRowCount();

KDTColumns columns = table.getColumns();

for (int i = 0; i <rowCount ; i++) {

BigDecimal dbSum = new BigDecimal("0");

for (int j = 0; j < columns.size(); j++) {

KDTColumn column = columns.getColumn(j);

String fieldName = column.getKey();

if (fieldName.startsWith("F")) { //判断是否 F 打头的列名

ICell cell = table.getRow(i).getCell(fieldName);


String cellValue = table.getCellDisplayText(cell);

if (cellValue != null) {

cellValue = cellValue.toString().replaceAll(",", "");

}

if (!StringUtility.isNumber(cellValue)) {

Object cellObj = cell.getValue();

if (cellObj != null)

cellValue = cellObj.toString();

if (!StringUtility.isNumber(cellValue)) {

continue;

}

}


BigDecimal bigdem = new BigDecimal(String

.valueOf(cellValue).trim());

dbSum = dbSum.add(bigdem);

}

}

String strSum = dbSum.toString();

columnMap.put(i, strSum);

}

Iterator valueIterator = columnMap.entrySet().iterator();

while (valueIterator.hasNext()) {

Map.Entry colEntry = (Map.Entry) valueIterator.next();

Integer rowIndex = (Integer) colEntry.getKey();

String colValue = (String) colEntry.getValue();

table.getCell(rowIndex, "Total").setValue(colValue);

}

}

-------------

代码调用:

SzReportUtils.appendFootRow(tblMain, fieldSumList);

SzReportUtils.appendTotal(tblMain);

 
http://hi.baidu.com/hipanda/item/2e2e4f44414cfe99df2a9ff7
0 0
原创粉丝点击