You are here

public static function PHPExcel_Calculation_MathTrig::SUMIF in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php \PHPExcel_Calculation_MathTrig::SUMIF()

* SUMIF * * Counts the number of cells that contain numbers within the list of arguments * * Excel Function: * SUMIF(value1[,value2[, ...]],condition) * * @access public * @category Mathematical and Trigonometric Functions *

Parameters

mixed $arg,... Data values: * @param string $condition The criteria that defines which cells will be summed. * @return float

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php, line 1158

Class

PHPExcel_Calculation_MathTrig
PHPExcel_Calculation_MathTrig

Code

public static function SUMIF($aArgs, $condition, $sumArgs = array()) {

  // Return value
  $returnValue = 0;
  $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs);
  $sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs);
  if (empty($sumArgs)) {
    $sumArgs = $aArgs;
  }
  $condition = PHPExcel_Calculation_Functions::_ifCondition($condition);

  // Loop through arguments
  foreach ($aArgs as $key => $arg) {
    if (!is_numeric($arg)) {
      $arg = str_replace('"', '""', $arg);
      $arg = PHPExcel_Calculation::_wrapResult(strtoupper($arg));
    }
    $testCondition = '=' . $arg . $condition;
    if (PHPExcel_Calculation::getInstance()
      ->_calculateFormulaValue($testCondition)) {

      // Is it a value within our criteria
      $returnValue += $sumArgs[$key];
    }
  }

  // Return
  return $returnValue;
}