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          }
  • 相关阅读:
    网络安全课 06 【Euler、Fermat定理、Miller-Rabin 概率算法】
    网络安全课 05 【保密通信、秘钥分发】
    网络安全课 04 【双重、三重DES】
    状压DP【蓝桥杯 2019_C++_A T9】
    蓝桥杯 2019 C++ A 题解
    凯撒加密【加密+暴力破解+文本单词匹配】
    蓝桥杯 2018 C++ A 题解 【除7、10】
    rest_framework 分页三种
    rest_framework 序列化篇
    rest_framework 解析器(下 全局配置使用)
  • 原文地址:https://www.cnblogs.com/lyc-smile/p/9211951.html
Copyright © 2011-2022 走看看