@Override
 public String getTextString() {
   StringBuilder sb = new StringBuilder();
   for (int j = 0; j < numOfCells; ++j) {
     CellValue cellValue = getCellValueAt(j);
     if (cellValue != null) {
       sb.append(cellValue.getStringValue());
     }
   }
   return sb.length() == 0 ? null : sb.toString();
 }
Exemple #2
0
 /**
  * セルに設定された計算式を評価して値を取得する
  *
  * @param nRow 行番号
  * @param nColumn 列番号
  * @return セルの値
  */
 public static Object getDataByEvaluateFormula(XSSFSheet sheet, int nRow, int nColumn) {
   assert sheet != null;
   XSSFRow row = getRowAnyway(sheet, nRow);
   if (row != null) {
     XSSFCell cell = row.getCell(nColumn);
     if (cell != null) {
       FormulaEvaluator eval = sheet.getWorkbook().getCreationHelper().createFormulaEvaluator();
       if (eval != null) {
         CellValue value = eval.evaluate(cell);
         if (value != null) {
           return value.getNumberValue();
         }
       }
     }
   }
   return null;
 }
Exemple #3
0
 public void setNestedTable(Table nestedTable, RepFactory factory) {
   this.nestedTable = nestedTable;
   // mariam
   if (nestedTable != null) {
     nestedTable.setNestedTableInNode(this);
     // pedro 2012-09-15
     if (!value.isEmptyValue()) {
       logger.info(
           "Node in column '"
               + factory.getColumnName(hNodeId)
               + "' contains both value and nested table: "
               + toString()
               + " -- setting value '"
               + value.asString()
               + "'");
       nestedTable.addOrphanValue(value, factory);
     }
   }
 }
Exemple #4
0
 @Override
 public void prettyPrint(String prefix, PrintWriter pw, RepFactory factory) {
   pw.print(prefix + "  - ");
   pw.print(factory.getHNode(hNodeId).getColumnName() + "/" + id + "/" + hNodeId + ":");
   if (nestedTable != null) {
     pw.println();
     nestedTable.prettyPrint(prefix + "      ", pw, factory);
   } else {
     pw.println("<" + value.asString() + ">");
   }
 }
Exemple #5
0
 public String toString() {
   StringBuffer b = new StringBuffer();
   b.append("N(");
   b.append(getId() + ",");
   b.append(hNodeId + ",");
   if (nestedTable != null) {
     b.append("*" + nestedTable.getId() + "/" + nestedTable.getHTableId() + ")");
   } else {
     b.append(value.asString() + ")");
   }
   return b.toString();
 }
Exemple #6
0
 public Cell(int rowIndex, int columnIndex, CellValue value) {
   this.rowIndex = rowIndex;
   this.columnIndex = columnIndex;
   this.value = value;
   // 初始化备选值
   this.whiteValues = new Vector<CellValue>();
   if (value == CellValue.Value_Empty) {
     for (CellValue cellValue : CellValue.values()) this.whiteValues.add(cellValue);
     this.whiteValues.remove(CellValue.Value_Empty);
   }
   // 初始化
   this.relatedRanges = new Vector<Range>();
 }
Exemple #7
0
  /** Writes out the data validations */
  private void writeDataValidation() throws IOException {
    if (dataValidation != null && validatedCells.size() == 0) {
      // only data validations are those read in
      dataValidation.write(outputFile);
      return;
    }

    if (dataValidation == null && validatedCells.size() > 0) {
      int comboBoxId =
          sheet.getComboBox() != null
              ? sheet.getComboBox().getObjectId()
              : DataValidation.DEFAULT_OBJECT_ID;
      dataValidation =
          new DataValidation(
              comboBoxId, sheet.getWorkbook(), sheet.getWorkbook(), workbookSettings);

      for (Iterator i = validatedCells.iterator(); i.hasNext(); ) {
        CellValue cv = (CellValue) i.next();
        CellFeatures cf = cv.getCellFeatures();
        DataValiditySettingsRecord dvsr = new DataValiditySettingsRecord(cf.getDVParser());
        dataValidation.add(dvsr);
      }
      dataValidation.write(outputFile);
      return;
    }

    // Read and write validations
    for (Iterator i = validatedCells.iterator(); i.hasNext(); ) {
      CellValue cv = (CellValue) i.next();
      CellFeatures cf = cv.getCellFeatures();
      DataValiditySettingsRecord dvsr = new DataValiditySettingsRecord(cf.getDVParser());
      dataValidation.add(dvsr);
    }
    dataValidation.write(outputFile);
    return;
  }
Exemple #8
0
 public void setValue(CellValue value, NodeStatus status, RepFactory factory) {
   this.value = value;
   this.status = status;
   // Pedro 2012/09/14
   if (nestedTable != null) {
     logger.info(
         "Node in column '"
             + factory.getColumnName(hNodeId)
             + "' contains both value and nested table: "
             + toString()
             + " -- setting value '"
             + value.asString()
             + "'");
     nestedTable.addOrphanValue(value, factory);
   }
 }
  private Object evaluateCellFormula(final HSSFWorkbook workbook, final Cell cell) {
    FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
    CellValue cellValue = evaluator.evaluate(cell);
    Object result = null;

    if (cellValue.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
      result = cellValue.getBooleanValue();
    } else if (cellValue.getCellType() == Cell.CELL_TYPE_NUMERIC) {
      result = cellValue.getNumberValue();
    } else if (cellValue.getCellType() == Cell.CELL_TYPE_STRING) {
      result = cellValue.getStringValue();
    }

    return result;
  }
Exemple #10
0
/** @author szekely */
public class Node extends RepEntity implements Neighbor {

  private static Logger logger = LoggerFactory.getLogger(Node.class);

  public enum NodeStatus {
    original("O"),
    edited("E");

    private String codedValue;

    private NodeStatus(String userLabel) {
      this.codedValue = userLabel;
    }

    public String getCodedStatus() {
      return codedValue;
    }
  }

  // the HNode that defines my properties.
  private final String hNodeId;

  // possibly has a nested table, null if none
  private Table nestedTable = null;

  private NodeStatus status = NodeStatus.original;

  // The value stored in this cell.
  private CellValue value = CellValue.getEmptyValue();

  private CellValue originalValue = CellValue.getEmptyValue();

  // mariam
  /** The row that this node belongs to */
  private Row belongsToRow;

  Node(String id, String hNodeId) {
    super(id);
    this.hNodeId = hNodeId;
  }

  // mariam
  public void setBelongsToRow(Row row) {
    belongsToRow = row;
  }

  public Row getBelongsToRow() {
    return belongsToRow;
  }

  /**
   * Return the table that this node belongs to.
   *
   * @return the table that this node belongs to.
   */
  public Table getParentTable() {
    return belongsToRow.getBelongsToTable();
  }

  // /////////////

  public String getHNodeId() {
    return hNodeId;
  }

  public NodeStatus getStatus() {
    return status;
  }

  public CellValue getOriginalValue() {
    return originalValue;
  }

  public CellValue getValue() {
    return value;
  }

  public void setValue(CellValue value, NodeStatus status, RepFactory factory) {
    this.value = value;
    this.status = status;
    // Pedro 2012/09/14
    if (nestedTable != null) {
      logger.info(
          "Node in column '"
              + factory.getColumnName(hNodeId)
              + "' contains both value and nested table: "
              + toString()
              + " -- setting value '"
              + value.asString()
              + "'");
      nestedTable.addOrphanValue(value, factory);
    }
  }

  public void clearValue(NodeStatus status) {
    // pedro 2012-09-15: this was wrong because it was setting the value to
    // null.
    this.value = CellValue.getEmptyValue();
    this.status = status;
  }

  public void setValue(String value, NodeStatus status, RepFactory factory) {
    setValue(new StringCellValue(value), status, factory);
  }

  public Table getNestedTable() {
    return nestedTable;
  }

  public void setNestedTable(Table nestedTable, RepFactory factory) {
    this.nestedTable = nestedTable;
    // mariam
    if (nestedTable != null) {
      nestedTable.setNestedTableInNode(this);
      // pedro 2012-09-15
      if (!value.isEmptyValue()) {
        logger.info(
            "Node in column '"
                + factory.getColumnName(hNodeId)
                + "' contains both value and nested table: "
                + toString()
                + " -- setting value '"
                + value.asString()
                + "'");
        nestedTable.addOrphanValue(value, factory);
      }
    }
  }

  public boolean hasNestedTable() {
    return nestedTable != null;
  }

  public String toString() {
    StringBuffer b = new StringBuffer();
    b.append("N(");
    b.append(getId() + ",");
    b.append(hNodeId + ",");
    if (nestedTable != null) {
      b.append("*" + nestedTable.getId() + "/" + nestedTable.getHTableId() + ")");
    } else {
      b.append(value.asString() + ")");
    }
    return b.toString();
  }

  @Override
  public void prettyPrint(String prefix, PrintWriter pw, RepFactory factory) {
    pw.print(prefix + "  - ");
    pw.print(factory.getHNode(hNodeId).getColumnName() + "/" + id + "/" + hNodeId + ":");
    if (nestedTable != null) {
      pw.println();
      nestedTable.prettyPrint(prefix + "      ", pw, factory);
    } else {
      pw.println("<" + value.asString() + ">");
    }
  }

  @Override
  public boolean canReachNeighbor(String hNodeId) {
    return belongsToRow.canReachNeighbor(hNodeId);
  }

  @Override
  public Node getNeighbor(String hNodeId) {
    return belongsToRow.getNeighbor(hNodeId);
  }

  @Override
  public Node getNeighborByColumnName(String columnName, RepFactory factory) {
    return belongsToRow.getNeighborByColumnName(columnName, factory);
  }
}
Exemple #11
0
 public void clearValue(NodeStatus status) {
   // pedro 2012-09-15: this was wrong because it was setting the value to
   // null.
   this.value = CellValue.getEmptyValue();
   this.status = status;
 }