Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.functions;
  16. import org.apache.poi.ss.formula.eval.BlankEval;
  17. import org.apache.poi.ss.formula.eval.ErrorEval;
  18. import org.apache.poi.ss.formula.eval.EvaluationException;
  19. import org.apache.poi.ss.formula.eval.OperandResolver;
  20. import org.apache.poi.ss.formula.eval.ValueEval;
  21. /**
  22. * Implementation of the DGet function:
  23. * Finds the value of a column in an area with given conditions.
  24. */
  25. public final class DGet implements IDStarAlgorithm {
  26. private ValueEval result;
  27. @Override
  28. public boolean processMatch(ValueEval eval) {
  29. if(result == null) // First match, just set the value.
  30. {
  31. result = eval;
  32. }
  33. else // There was a previous match, since there is only exactly one allowed, bail out.
  34. {
  35. result = ErrorEval.NUM_ERROR;
  36. return false;
  37. }
  38. return true;
  39. }
  40. @Override
  41. public ValueEval getResult() {
  42. if(result == null) {
  43. return ErrorEval.VALUE_INVALID;
  44. } else if(result instanceof BlankEval) {
  45. return ErrorEval.VALUE_INVALID;
  46. } else
  47. try {
  48. if(OperandResolver.coerceValueToString(OperandResolver.getSingleValue(result, 0, 0)).equals("")) {
  49. return ErrorEval.VALUE_INVALID;
  50. }
  51. else {
  52. return result;
  53. }
  54. } catch (EvaluationException e) {
  55. return e.getErrorEval();
  56. }
  57. }
  58. }