コード例 #1
1
ファイル: HSSFDataFormat.java プロジェクト: aw1621107/hacks
  /**
   * Get the format index that matches the given format string, creating a new format entry if
   * required. Aliases text to the proper format as required.
   *
   * @param pFormat string matching a built in format
   * @return index of format.
   */
  public short getFormat(String pFormat) {
    // Normalise the format string
    String format;
    if (pFormat.toUpperCase(Locale.ROOT).equals("TEXT")) {
      format = "@";
    } else {
      format = pFormat;
    }

    // Merge in the built in formats if we haven't already
    if (!_movedBuiltins) {
      for (int i = 0; i < _builtinFormats.length; i++) {
        ensureFormatsSize(i);
        if (_formats.get(i) == null) {
          _formats.set(i, _builtinFormats[i]);
        } else {
          // The workbook overrides this default format
        }
      }
      _movedBuiltins = true;
    }

    // See if we can find it
    for (int i = 0; i < _formats.size(); i++) {
      if (format.equals(_formats.get(i))) {
        return (short) i;
      }
    }

    // We can't find it, so add it as a new one
    short index = _workbook.getFormat(format, true);
    ensureFormatsSize(index);
    _formats.set(index, format);
    return index;
  }
コード例 #2
0
ファイル: HSSFDataFormat.java プロジェクト: aw1621107/hacks
  /**
   * Constructs a new data formatter. It takes a workbook to have access to the workbooks format
   * records.
   *
   * @param workbook the workbook the formats are tied to.
   */
  HSSFDataFormat(InternalWorkbook workbook) {
    _workbook = workbook;

    Iterator<FormatRecord> i = workbook.getFormats().iterator();
    while (i.hasNext()) {
      FormatRecord r = i.next();
      ensureFormatsSize(r.getIndexCode());
      _formats.set(r.getIndexCode(), r.getFormatString());
    }
  }