zoukankan      html  css  js  c++  java
  • KDTable如何添加合计行?

     1      /**
     2       * 功能:添加合计行
     3       * 
     4       * @param table
     5       *            指定的KDTable
     6       * @param fields
     7       *            需要合计的列
     8       */
     9      public static void apendFootRow(KDTable table, String fields[]) {
    10       int size = fields.length;
    11       if (size == 0)
    12        return;
    13       Map sumValue = new HashMap();
    14       // 利用getRowCount的到的行可能不正确
    15       int count = table.getRowCount3();
    16 
    17       for (int i = 0; i < fields.length; i++) {
    18        sumValue.put(fields[i], new BigDecimal("0.00"));
    19       }
    20       IRow footRow = null;
    21       KDTFootManager footManager = table.getFootManager();
    22       if (footManager == null) {
    23        footManager = new KDTFootManager(table);
    24        footManager.addFootView();
    25        table.setFootManager(footManager);
    26       }
    27       // 计算所有指定行的合计值
    28       footRow = footManager.getFootRow(0);
    29       for (int i = 0; i < count; i++) {
    30        IRow row = table.getRow(i);
    31        for (int j = 0; j < fields.length; j++) {
    32         sumValueForCell(row, fields[j], sumValue);
    33        }
    34       }
    35 
    36       if (footRow == null) {
    37        footRow = footManager.addFootRow(0);
    38       }
    39       // 设置合计行显示样式
    40       String colFormat = "%{0.00}f";
    41 
    42       String total = EASResource.getString(FrameWorkClientUtils.strResource
    43         + "Msg_Total");
    44 
    45       table.getIndexColumn().setWidthAdjustMode(KDTIndexColumn.WIDTH_MANUAL);
    46       table.getIndexColumn().setWidth(30);
    47       footManager.addIndexText(0, total);
    48       footRow.getStyleAttributes().setBackground(new Color(0xf6, 0xf6, 0xbf));
    49       for (int i = 0; i < size; i++) {
    50        String colName = fields[i];
    51        footRow.getCell(colName).getStyleAttributes().setNumberFormat(
    52          colFormat);
    53        footRow.getCell(colName).getStyleAttributes().setHorizontalAlign(
    54          HorizontalAlignment.RIGHT);
    55        footRow.getCell(colName).getStyleAttributes().setFontColor(
    56          Color.black);
    57       }
    58 
    59       // 设置合计行的值
    60       for (int i = 0; i < fields.length; i++) {
    61        footRow.getCell(fields[i]).setValue(sumValue.get(fields[i]));
    62       }
    63      }
    64      
    65      private static void sumValueForCell(IRow row, String key, Map sumValue) {
    66           ICell cell = row.getCell(key);
    67 
    68           if (cell != null) {
    69            Object obj = cell.getValue();
    70            if (obj != null) {
    71             BigDecimal keyValue = (BigDecimal) sumValue.get(key);
    72             keyValue = keyValue.add(new BigDecimal(obj.toString()));
    73             sumValue.put(key, keyValue);
    74            }
    75           }
    76          }
  • 相关阅读:
    “耐撕”团队 2016.03.25 站立会议
    [Java面试二]Java基础知识精华部分.
    [Java面试一]面试复习大纲.
    [Java面试四]Strust2总结及在面试中的一些问题.
    [Java面试五]Spring总结以及在面试中的一些问题.
    [Java面试六]SpringMVC总结以及在面试中的一些问题.
    [Java面试七]Mybatis总结以及在面试中的一些问题.
    Hibernate总结以及在面试中的一些问题.
    脚本语言知识总结.
    浏览器跨域问题.
  • 原文地址:https://www.cnblogs.com/lyc-smile/p/9211951.html
Copyright © 2011-2022 走看看