zoukankan      html  css  js  c++  java
  • KDTable公式解析提示信息设置

    KDTable扩展功能
     
    一、KDTable支持类似Excel公式的功能,当计算单元格出现错误时,如数据非法、被零除等错误信息如何进行设置?
     
    详见下文:
     
    1、定义信息提示解析类:
     
     1 public class AnlysScriptErrorReport implements IScriptErrorHandler {
     2 
     3     private String errorDiv0_DefaltValue = null;
     4 
     5     public AnlysScriptErrorReport() {
     6     }
     7 
     8     public void setDiv0Value(String defaultValue) {
     9         this.errorDiv0_DefaltValue = defaultValue;
    10     }
    11 
    12     public void handle(KDTable table, Exception exception, CellPosition cellPos, String scriptSource, int pos) {
    13         if (pos == -1 || cellPos == null) {
    14             exception.printStackTrace();
    15         } else {
    16             if (table != null) {
    17                 /*
    18                  * 设置当公式是除且是除以0时显示的默认信息: 默认是显示:#DIV0 除数为零
    19                  * 可以通过该方法设置默认要显示的值:如可以设置为0,或-
    20                  */
    21                 String errorMessage = exception.getMessage();
    22                 if (exception instanceof SyntaxErrorException) {
    23                     SyntaxErrorException e = (SyntaxErrorException) exception;
    24                     long errorCode = e.getErrorCode();
    25                     if (errorCode == ExprError.Div0) {// 如果是除数为零的Exception,错误信息特别处理
    26                         errorMessage = "";
    27                     } else if (errorCode == ExprError.BadValue) {
    28                         errorMessage = "";
    29                     }
    30                 }
    31                 table.getRow(cellPos.row).getCell(cellPos.col).getKDTCell().setValue(errorMessage);
    32             }
    33         }
    34     }
    35 }
    2、应用信息解析类:
    table.getScriptManager().setErrorHandler(new AnlysScriptErrorReport());
     
     二、单元格为0的显示格式扩展
     
    1、定义表格单元格内容显示器
     
     1 public class AnlysFilterZeroParser implements IUserCellDisplayParser {
     2 
     3     public Object parse(int rowIndex, int colIndex, ICell cell, Object value) {
     4         if(value==null) return value;
     5         String strValue=value.toString();
     6         
     7         if("0".equals(strValue) || "0.0".equals(strValue) || "0.00%".equals(strValue)) {
     8             return "";
     9         }
    10         return value;
    11     }
    12 }
     
    2、应用单元格内容显示:
    table.setUserCellDisplayParser(new AnlysFilterZeroParser());
     
  • 相关阅读:
    Oracle Core 学习笔记一 Redo 和 Undo 机制详解
    Oracle Linux 6.1 平台安装 Database 11gR2 步骤 说明
    Oracle 查看表空间使用率 SQL 脚本
    Oracle 单实例 Relink Binary Options 说明
    Oracle Linux 6 下 Oracle RDBMS Server 11gR2 Preinstall RPM 包说明
    Oracle DBLink 访问Lob 字段 ORA22992 解决方法
    Oracle 10g 对象 默认 ITL 数量 测试
    Oracle Core 学习笔记一 Redo 和 Undo 机制详解
    与系统 性能相关的 常见十个瓶颈 说明
    Oracle 11g UNDO 管理 详解
  • 原文地址:https://www.cnblogs.com/masb/p/3012090.html
Copyright © 2011-2022 走看看