You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SheetRangeEvaluator.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.formula;
  16. import org.apache.poi.ss.formula.eval.ValueEval;
  17. /**
  18. * Evaluator for returning cells or sheets for a range of sheets
  19. */
  20. final class SheetRangeEvaluator {
  21. private final int _firstSheetIndex;
  22. private final int _lastSheetIndex;
  23. private SheetRefEvaluator[] _sheetEvaluators;
  24. public SheetRangeEvaluator(int firstSheetIndex, int lastSheetIndex, SheetRefEvaluator[] sheetEvaluators) {
  25. if (firstSheetIndex < 0) {
  26. throw new IllegalArgumentException("Invalid firstSheetIndex: " + firstSheetIndex + ".");
  27. }
  28. if (lastSheetIndex < firstSheetIndex) {
  29. throw new IllegalArgumentException("Invalid lastSheetIndex: " + lastSheetIndex + " for firstSheetIndex: " + firstSheetIndex + ".");
  30. }
  31. _firstSheetIndex = firstSheetIndex;
  32. _lastSheetIndex = lastSheetIndex;
  33. _sheetEvaluators = sheetEvaluators;
  34. }
  35. public SheetRefEvaluator getSheetEvaluator(int sheetIndex) {
  36. if (sheetIndex < _firstSheetIndex || sheetIndex > _lastSheetIndex) {
  37. throw new IllegalArgumentException("Invalid SheetIndex: " + sheetIndex +
  38. " - Outside range " + _firstSheetIndex + " : " + _lastSheetIndex);
  39. }
  40. return _sheetEvaluators[sheetIndex-_firstSheetIndex];
  41. }
  42. public String getSheetName(int sheetIndex) {
  43. return getSheetEvaluator(sheetIndex).getSheetName();
  44. }
  45. public ValueEval getEvalForCell(int sheetIndex, int rowIndex, int columnIndex) {
  46. return getSheetEvaluator(sheetIndex).getEvalForCell(rowIndex, columnIndex);
  47. }
  48. }