Exemple #1
0
  /**
   * Gets the name of the external sheet specified by the index
   *
   * @param index the external sheet index
   * @return the name of the external sheet
   */
  public String getLastExternalSheetName(int index) {
    // For biff7, the whole external reference thing works differently
    // Hopefully for our purposes sheet references will all be local
    if (workbookBof.isBiff7()) {
      BoundsheetRecord br = (BoundsheetRecord) boundsheets.get(index);

      return br.getName();
    }

    int supbookIndex = externSheet.getSupbookIndex(index);
    SupbookRecord sr = (SupbookRecord) supbooks.get(supbookIndex);

    int lastTab = externSheet.getLastTabIndex(index);

    if (sr.getType() == SupbookRecord.INTERNAL) {
      // It's an internal reference - get the name from the boundsheets list
      BoundsheetRecord br = (BoundsheetRecord) boundsheets.get(lastTab);

      return br.getName();
    } else if (sr.getType() == SupbookRecord.EXTERNAL) {
      // External reference - get the sheet name from the supbook record
      StringBuffer sb = new StringBuffer();
      sb.append('[');
      sb.append(sr.getFileName());
      sb.append(']');
      sb.append(sr.getSheetName(lastTab));
      return sb.toString();
    }

    // An unknown supbook - return unkown
    return "[UNKNOWN]";
  }
  /**
   * Gets the name of the external sheet specified by the index
   *
   * @param index the external sheet index
   * @return the name of the external sheet
   */
  public String getLastExternalSheetName(int index) {
    // For biff7, the whole external reference thing works differently
    // Hopefully for our purposes sheet references will all be local
    if (workbookBof.isBiff7()) {
      BoundsheetRecord br = (BoundsheetRecord) boundsheets.get(index);

      return br.getName();
    }

    int supbookIndex = externSheet.getSupbookIndex(index);
    SupbookRecord sr = (SupbookRecord) supbooks.get(supbookIndex);

    int lastTab = externSheet.getLastTabIndex(index);

    if (sr.getType() == SupbookRecord.INTERNAL) {
      // It's an internal reference - get the name from the boundsheets list
      if (lastTab == 65535) {
        return "#REF";
      } else {
        BoundsheetRecord br = (BoundsheetRecord) boundsheets.get(lastTab);
        return br.getName();
      }
    } else if (sr.getType() == SupbookRecord.EXTERNAL) {
      // External reference - get the sheet name from the supbook record
      StringBuffer sb = new StringBuffer();
      java.io.File fl = new java.io.File(sr.getFileName());
      sb.append("'");
      sb.append(fl.getAbsolutePath());
      sb.append("[");
      sb.append(fl.getName());
      sb.append("]");
      sb.append((lastTab == 65535) ? "#REF" : sr.getSheetName(lastTab));
      sb.append("'");
      return sb.toString();
    }

    // An unknown supbook - return unkown
    logger.warn("Unknown Supbook 4");
    return "[UNKNOWN]";
  }
Exemple #3
0
  /**
   * Package protected function which gets the real internal sheet index based upon the external
   * sheet reference. This is used for extern sheet references which are specified in formulas
   *
   * @param index the external sheet reference
   * @return the actual sheet index
   */
  public int getLastExternalSheetIndex(int index) {
    // For biff7, the whole external reference thing works differently
    // Hopefully for our purposes sheet references will all be local
    if (workbookBof.isBiff7()) {
      return index;
    }

    Assert.verify(externSheet != null);

    int lastTab = externSheet.getLastTabIndex(index);

    return lastTab;
  }
  /**
   * Gets the name of the external sheet specified by the index
   *
   * @param index the external sheet index
   * @return the name of the external sheet
   */
  public String getExternalSheetName(int index) {
    // For biff7, the whole external reference thing works differently
    // Hopefully for our purposes sheet references will all be local
    if (workbookBof.isBiff7()) {
      BoundsheetRecord br = (BoundsheetRecord) boundsheets.get(index);

      return br.getName();
    }

    int supbookIndex = externSheet.getSupbookIndex(index);
    SupbookRecord sr = (SupbookRecord) supbooks.get(supbookIndex);

    int firstTab = externSheet.getFirstTabIndex(index);
    int lastTab = externSheet.getLastTabIndex(index);
    String firstTabName = "";
    String lastTabName = "";

    if (sr.getType() == SupbookRecord.INTERNAL) {
      // It's an internal reference - get the name from the boundsheets list
      if (firstTab == 65535) {
        firstTabName = "#REF";
      } else {
        BoundsheetRecord br = (BoundsheetRecord) boundsheets.get(firstTab);
        firstTabName = br.getName();
      }

      if (lastTab == 65535) {
        lastTabName = "#REF";
      } else {
        BoundsheetRecord br = (BoundsheetRecord) boundsheets.get(lastTab);
        lastTabName = br.getName();
      }

      String sheetName = (firstTab == lastTab) ? firstTabName : firstTabName + ':' + lastTabName;

      // if the sheet name contains apostrophes then escape them
      sheetName =
          sheetName.indexOf('\'') == -1 ? sheetName : StringHelper.replace(sheetName, "\'", "\'\'");

      // if the sheet name contains spaces, then enclose in quotes
      return sheetName.indexOf(' ') == -1 ? sheetName : '\'' + sheetName + '\'';
    } else if (sr.getType() == SupbookRecord.EXTERNAL) {
      // External reference - get the sheet name from the supbook record
      StringBuffer sb = new StringBuffer();
      java.io.File fl = new java.io.File(sr.getFileName());
      sb.append("'");
      sb.append(fl.getAbsolutePath());
      sb.append("[");
      sb.append(fl.getName());
      sb.append("]");
      sb.append((firstTab == 65535) ? "#REF" : sr.getSheetName(firstTab));
      if (lastTab != firstTab) {
        sb.append(sr.getSheetName(lastTab));
      }
      sb.append("'");
      return sb.toString();
    }

    // An unknown supbook - return unkown
    logger.warn("Unknown Supbook 3");
    return "[UNKNOWN]";
  }