Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
malles committed Mar 3, 2020
2 parents 8dac46c + c2a205e commit 304a331
Show file tree
Hide file tree
Showing 75 changed files with 1,171 additions and 433 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@ and this project adheres to [Semantic Versioning](https://semver.org).
## [Unreleased]

- Fix loading styles from vmlDrawings when containing whitespace [#1347](/~https://github.com/PHPOffice/PhpSpreadsheet/issues/1347)

## [1.11.0] - 2020-03-02

### Added

- Added support for the BASE function
- Added support for the ARABIC function
- Conditionals - Extend Support for (NOT)CONTAINSBLANKS [#1278](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1278)

### Fixed

- Handle Error in Formula Processing Better for Xls [#1267](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1267)
- Handle ConditionalStyle NumberFormat When Reading Xlsx File [#1296](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1296)
- Fix Xlsx Writer's handling of decimal commas [#1282](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1282)
- Fix for issue by removing test code mistakenly left in [#1328](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1328)
- Fix for Xls writer wrong selected cells and active sheet [#1256](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1256)
- Fix active cell when freeze pane is used [#1323](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1323)
- Fix XLSX file loading with autofilter containing '$' [#1326](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1326)
- PHPDoc - Use `@return $this` for fluent methods [#1362](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/1362)

## [1.10.1] - 2019-12-02

Expand Down
5 changes: 5 additions & 0 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ class Calculation
'functionCall' => [Functions::class, 'DUMMY'],
'argumentCount' => '1',
],
'BASE' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'BASE'],
'argumentCount' => '2,3',
],
'BESSELI' => [
'category' => Category::CATEGORY_ENGINEERING,
'functionCall' => [Engineering::class, 'BESSELI'],
Expand Down
134 changes: 89 additions & 45 deletions src/PhpSpreadsheet/Calculation/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,8 @@ public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
*
* Excel Function:
* YEARFRAC(startDate,endDate[,method])
* See https://lists.oasis-open.org/archives/office-formula/200806/msg00039.html
* for description of algorithm used in Excel
*
* @category Date/Time Functions
*
Expand Down Expand Up @@ -906,6 +908,11 @@ public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
if (is_string($endDate = self::getDateValue($endDate))) {
return Functions::VALUE();
}
if ($startDate > $endDate) {
$temp = $startDate;
$startDate = $endDate;
$endDate = $temp;
}

if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) {
switch ($method) {
Expand All @@ -916,46 +923,43 @@ public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
$startYear = self::YEAR($startDate);
$endYear = self::YEAR($endDate);
$years = $endYear - $startYear + 1;
$leapDays = 0;
$startMonth = self::MONTHOFYEAR($startDate);
$startDay = self::DAYOFMONTH($startDate);
$endMonth = self::MONTHOFYEAR($endDate);
$endDay = self::DAYOFMONTH($endDate);
$startMonthDay = 100 * $startMonth + $startDay;
$endMonthDay = 100 * $endMonth + $endDay;
if ($years == 1) {
if (self::isLeapYear($endYear)) {
$startMonth = self::MONTHOFYEAR($startDate);
$endMonth = self::MONTHOFYEAR($endDate);
$endDay = self::DAYOFMONTH($endDate);
if (($startMonth < 3) ||
(($endMonth * 100 + $endDay) >= (2 * 100 + 29))) {
$leapDays += 1;
}
$tmpCalcAnnualBasis = 366;
} else {
$tmpCalcAnnualBasis = 365;
}
} else {
for ($year = $startYear; $year <= $endYear; ++$year) {
if ($year == $startYear) {
$startMonth = self::MONTHOFYEAR($startDate);
$startDay = self::DAYOFMONTH($startDate);
if ($startMonth < 3) {
$leapDays += (self::isLeapYear($year)) ? 1 : 0;
}
} elseif ($year == $endYear) {
$endMonth = self::MONTHOFYEAR($endDate);
$endDay = self::DAYOFMONTH($endDate);
if (($endMonth * 100 + $endDay) >= (2 * 100 + 29)) {
$leapDays += (self::isLeapYear($year)) ? 1 : 0;
}
} elseif ($years == 2 && $startMonthDay >= $endMonthDay) {
if (self::isLeapYear($startYear)) {
if ($startMonthDay <= 229) {
$tmpCalcAnnualBasis = 366;
} else {
$leapDays += (self::isLeapYear($year)) ? 1 : 0;
$tmpCalcAnnualBasis = 365;
}
}
if ($years == 2) {
if (($leapDays == 0) && (self::isLeapYear($startYear)) && ($days > 365)) {
$leapDays = 1;
} elseif ($days < 366) {
$years = 1;
} elseif (self::isLeapYear($endYear)) {
if ($endMonthDay >= 229) {
$tmpCalcAnnualBasis = 366;
} else {
$tmpCalcAnnualBasis = 365;
}
} else {
$tmpCalcAnnualBasis = 365;
}
$leapDays /= $years;
} else {
$tmpCalcAnnualBasis = 0;
for ($year = $startYear; $year <= $endYear; ++$year) {
$tmpCalcAnnualBasis += self::isLeapYear($year) ? 366 : 365;
}
$tmpCalcAnnualBasis /= $years;
}

return $days / (365 + $leapDays);
return $days / $tmpCalcAnnualBasis;
case 2:
return self::DATEDIF($startDate, $endDate) / 360;
case 3:
Expand Down Expand Up @@ -1273,6 +1277,36 @@ public static function WEEKDAY($dateValue = 1, $style = 1)
return $DoW;
}

const STARTWEEK_SUNDAY = 1;
const STARTWEEK_MONDAY = 2;
const STARTWEEK_MONDAY_ALT = 11;
const STARTWEEK_TUESDAY = 12;
const STARTWEEK_WEDNESDAY = 13;
const STARTWEEK_THURSDAY = 14;
const STARTWEEK_FRIDAY = 15;
const STARTWEEK_SATURDAY = 16;
const STARTWEEK_SUNDAY_ALT = 17;
const DOW_SUNDAY = 1;
const DOW_MONDAY = 2;
const DOW_TUESDAY = 3;
const DOW_WEDNESDAY = 4;
const DOW_THURSDAY = 5;
const DOW_FRIDAY = 6;
const DOW_SATURDAY = 7;
const STARTWEEK_MONDAY_ISO = 21;
const METHODARR = [
self::STARTWEEK_SUNDAY => self::DOW_SUNDAY,
self::DOW_MONDAY,
self::STARTWEEK_MONDAY_ALT => self::DOW_MONDAY,
self::DOW_TUESDAY,
self::DOW_WEDNESDAY,
self::DOW_THURSDAY,
self::DOW_FRIDAY,
self::DOW_SATURDAY,
self::DOW_SUNDAY,
self::STARTWEEK_MONDAY_ISO => self::STARTWEEK_MONDAY_ISO,
];

/**
* WEEKNUM.
*
Expand All @@ -1291,41 +1325,51 @@ public static function WEEKDAY($dateValue = 1, $style = 1)
* @param int $method Week begins on Sunday or Monday
* 1 or omitted Week begins on Sunday.
* 2 Week begins on Monday.
* 11 Week begins on Monday.
* 12 Week begins on Tuesday.
* 13 Week begins on Wednesday.
* 14 Week begins on Thursday.
* 15 Week begins on Friday.
* 16 Week begins on Saturday.
* 17 Week begins on Sunday.
* 21 ISO (Jan. 4 is week 1, begins on Monday).
*
* @return int|string Week Number
*/
public static function WEEKNUM($dateValue = 1, $method = 1)
public static function WEEKNUM($dateValue = 1, $method = self::STARTWEEK_SUNDAY)
{
$dateValue = Functions::flattenSingleValue($dateValue);
$method = Functions::flattenSingleValue($method);

if (!is_numeric($method)) {
return Functions::VALUE();
} elseif (($method < 1) || ($method > 2)) {
return Functions::NAN();
}
$method = floor($method);
$method = (int) $method;
if (!array_key_exists($method, self::METHODARR)) {
return Functions::NaN();
}
$method = self::METHODARR[$method];

if ($dateValue === null) {
$dateValue = 1;
} elseif (is_string($dateValue = self::getDateValue($dateValue))) {
$dateValue = self::getDateValue($dateValue);
if (is_string($dateValue)) {
return Functions::VALUE();
} elseif ($dateValue < 0.0) {
}
if ($dateValue < 0.0) {
return Functions::NAN();
}

// Execute function
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
if ($method == self::STARTWEEK_MONDAY_ISO) {
return (int) $PHPDateObject->format('W');
}
$dayOfYear = $PHPDateObject->format('z');
$PHPDateObject->modify('-' . $dayOfYear . ' days');
$firstDayOfFirstWeek = $PHPDateObject->format('w');
$daysInFirstWeek = (6 - $firstDayOfFirstWeek + $method) % 7;
$interval = $dayOfYear - $daysInFirstWeek;
$weekOfYear = floor($interval / 7) + 1;

if ($daysInFirstWeek) {
++$weekOfYear;
}
$daysInFirstWeek += 7 * !$daysInFirstWeek;
$endFirstWeek = $daysInFirstWeek - 1;
$weekOfYear = floor(($dayOfYear - $endFirstWeek + 13) / 7);

return (int) $weekOfYear;
}
Expand Down
43 changes: 43 additions & 0 deletions src/PhpSpreadsheet/Calculation/MathTrig.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,49 @@ public static function ATAN2($xCoordinate = null, $yCoordinate = null)
return Functions::VALUE();
}

/**
* BASE.
*
* Converts a number into a text representation with the given radix (base).
*
* Excel Function:
* BASE(Number, Radix [Min_length])
*
* @category Mathematical and Trigonometric Functions
*
* @param float $number
* @param float $radix
* @param int $minLength
*
* @return string the text representation with the given radix (base)
*/
public static function BASE($number, $radix, $minLength = null)
{
$number = Functions::flattenSingleValue($number);
$radix = Functions::flattenSingleValue($radix);
$minLength = Functions::flattenSingleValue($minLength);

if (is_numeric($number) && is_numeric($radix) && ($minLength === null || is_numeric($minLength))) {
// Truncate to an integer
$number = (int) $number;
$radix = (int) $radix;
$minLength = (int) $minLength;

if ($number < 0 || $number >= 2 ** 53 || $radix < 2 || $radix > 36) {
return Functions::NAN(); // Numeric range constraints
}

$outcome = strtoupper((string) base_convert($number, 10, $radix));
if ($minLength !== null) {
$outcome = str_pad($outcome, $minLength, '0', STR_PAD_LEFT); // String padding
}

return $outcome;
}

return Functions::VALUE();
}

/**
* CEILING.
*
Expand Down
1 change: 1 addition & 0 deletions src/PhpSpreadsheet/Calculation/functionlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ AVERAGEA
AVERAGEIF
AVERAGEIFS
BAHTTEXT
BASE
BESSELI
BESSELJ
BESSELK
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Cell/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Cell
/**
* Update the cell into the cell collection.
*
* @return self
* @return $this
*/
public function updateInCollection()
{
Expand Down Expand Up @@ -177,7 +177,7 @@ public function getFormattedValue()
*
* @throws Exception
*
* @return Cell
* @return $this
*/
public function setValue($pValue)
{
Expand Down Expand Up @@ -672,7 +672,7 @@ public function setXfIndex($pValue)
*
* @param mixed $pAttributes
*
* @return Cell
* @return $this
*/
public function setFormulaAttributes($pAttributes)
{
Expand Down
Loading

0 comments on commit 304a331

Please sign in to comment.