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.

EvaluationWorkbook.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.SpreadsheetVersion;
  17. import org.apache.poi.ss.formula.ptg.NamePtg;
  18. import org.apache.poi.ss.formula.ptg.NameXPtg;
  19. import org.apache.poi.ss.formula.ptg.Ptg;
  20. import org.apache.poi.ss.formula.udf.UDFFinder;
  21. import org.apache.poi.util.Internal;
  22. /**
  23. * Abstracts a workbook for the purpose of formula evaluation.
  24. */
  25. @Internal
  26. public interface EvaluationWorkbook {
  27. String getSheetName(int sheetIndex);
  28. /**
  29. * @return -1 if the specified sheet is from a different book
  30. */
  31. int getSheetIndex(EvaluationSheet sheet);
  32. /**
  33. * Finds a sheet index by case insensitive name.
  34. * @return the index of the sheet matching the specified name. -1 if not found
  35. */
  36. int getSheetIndex(String sheetName);
  37. EvaluationSheet getSheet(int sheetIndex);
  38. /**
  39. * HSSF Only - fetch the external-style sheet details
  40. * <p>Return will have no workbook set if it's actually in our own workbook</p>
  41. */
  42. ExternalSheet getExternalSheet(int externSheetIndex);
  43. /**
  44. * XSSF Only - fetch the external-style sheet details
  45. * <p>Return will have no workbook set if it's actually in our own workbook</p>
  46. */
  47. ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber);
  48. /**
  49. * HSSF Only - convert an external sheet index to an internal sheet index,
  50. * for an external-style reference to one of this workbook's own sheets
  51. */
  52. int convertFromExternSheetIndex(int externSheetIndex);
  53. /**
  54. * HSSF Only - fetch the external-style name details
  55. */
  56. ExternalName getExternalName(int externSheetIndex, int externNameIndex);
  57. /**
  58. * XSSF Only - fetch the external-style name details
  59. */
  60. ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber);
  61. EvaluationName getName(NamePtg namePtg);
  62. EvaluationName getName(String name, int sheetIndex);
  63. String resolveNameXText(NameXPtg ptg);
  64. Ptg[] getFormulaTokens(EvaluationCell cell);
  65. UDFFinder getUDFFinder();
  66. SpreadsheetVersion getSpreadsheetVersion();
  67. /**
  68. * Propagated from {@link WorkbookEvaluator#clearAllCachedResultValues()} to clear locally cached data.
  69. * Implementations must call the same method on all referenced {@link EvaluationSheet} instances, as well as clearing local caches.
  70. * @see WorkbookEvaluator#clearAllCachedResultValues()
  71. *
  72. * @since POI 3.15 beta 3
  73. */
  74. void clearAllCachedResultValues();
  75. class ExternalSheet {
  76. private final String _workbookName;
  77. private final String _sheetName;
  78. public ExternalSheet(String workbookName, String sheetName) {
  79. _workbookName = workbookName;
  80. _sheetName = sheetName;
  81. }
  82. public String getWorkbookName() {
  83. return _workbookName;
  84. }
  85. public String getSheetName() {
  86. return _sheetName;
  87. }
  88. }
  89. class ExternalSheetRange extends ExternalSheet {
  90. private final String _lastSheetName;
  91. public ExternalSheetRange(String workbookName, String firstSheetName, String lastSheetName) {
  92. super(workbookName, firstSheetName);
  93. this._lastSheetName = lastSheetName;
  94. }
  95. public String getFirstSheetName() {
  96. return getSheetName();
  97. }
  98. public String getLastSheetName() {
  99. return _lastSheetName;
  100. }
  101. }
  102. class ExternalName {
  103. private final String _nameName;
  104. private final int _nameNumber;
  105. private final int _ix;
  106. public ExternalName(String nameName, int nameNumber, int ix) {
  107. _nameName = nameName;
  108. _nameNumber = nameNumber;
  109. _ix = ix;
  110. }
  111. public String getName() {
  112. return _nameName;
  113. }
  114. public int getNumber() {
  115. return _nameNumber;
  116. }
  117. public int getIx() {
  118. return _ix;
  119. }
  120. }
  121. }