Skip to content

Commit

Permalink
Merge branch 'master' into atsign
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Aug 2, 2024
2 parents 768dd75 + 1c77e00 commit f3ae0bd
Show file tree
Hide file tree
Showing 52 changed files with 121 additions and 144 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).

- Html Reader Preserve Unicode Whitespace. [Issue #1284](https://github.com/PHPOffice/PhpSpreadsheet/issues/1284) [PR #4106](https://github.com/PHPOffice/PhpSpreadsheet/pull/4106)
- RATE Function Floating Point Number of Periods. [PR #4107](https://github.com/PHPOffice/PhpSpreadsheet/pull/4107)
- Parameter Name Change Xlsx Writer Workbook. [Issue #4108](https://github.com/PHPOffice/PhpSpreadsheet/issues/4108) [PR #4111](https://github.com/PHPOffice/PhpSpreadsheet/pull/4111)
- New Algorithm for TRUNC, ROUNDUP, ROUNDDOWN. [Issue #4113](https://github.com/PHPOffice/PhpSpreadsheet/issues/4113) [PR #4115](https://github.com/PHPOffice/PhpSpreadsheet/pull/4115)

## 2024-07-29 - 2.2.1

Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class Calculation

/**
* Instance of this class.
*
* @var ?Calculation
*/
private static ?Calculation $instance = null;

Expand Down Expand Up @@ -3316,10 +3314,8 @@ private static function translateFormula(array $from, array $to, string $formula
return $formula;
}

/** @var ?array */
private static ?array $functionReplaceFromExcel;

/** @var ?array */
private static ?array $functionReplaceToLocale;

/**
Expand Down Expand Up @@ -3365,10 +3361,8 @@ public function translateFormulaToLocale(string $formula): string
);
}

/** @var ?array */
private static ?array $functionReplaceFromLocale;

/** @var ?array */
private static ?array $functionReplaceToExcel;

/**
Expand Down
33 changes: 27 additions & 6 deletions src/PhpSpreadsheet/Calculation/MathTrig/Round.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class Round
{
use ArrayEnabled;

private const ROUNDING_ADJUSTMENT = (PHP_VERSION_ID < 80400) ? 0 : 1e-14;

/**
* ROUND.
*
Expand Down Expand Up @@ -69,11 +67,22 @@ public static function up($number, $digits): array|string|float
return 0.0;
}

$digitsPlus1 = $digits + 1;
if ($number < 0.0) {
return round($number - 0.5 * 0.1 ** $digits + self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_DOWN);
if ($digitsPlus1 < 0) {
return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
}
$result = sprintf("%.{$digitsPlus1}F", $number - 0.5 * 0.1 ** $digits);

return round((float) $result, $digits, PHP_ROUND_HALF_DOWN);
}

if ($digitsPlus1 < 0) {
return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
}
$result = sprintf("%.{$digitsPlus1}F", $number + 0.5 * 0.1 ** $digits);

return round($number + 0.5 * 0.1 ** $digits - self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_DOWN);
return round((float) $result, $digits, PHP_ROUND_HALF_DOWN);
}

/**
Expand Down Expand Up @@ -105,11 +114,23 @@ public static function down($number, $digits): array|string|float
return 0.0;
}

$digitsPlus1 = $digits + 1;
if ($number < 0.0) {
return round($number + 0.5 * 0.1 ** $digits - self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_UP);
if ($digitsPlus1 < 0) {
return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
}
$result = sprintf("%.{$digitsPlus1}F", $number + 0.5 * 0.1 ** $digits);

return round((float) $result, $digits, PHP_ROUND_HALF_UP);
}

if ($digitsPlus1 < 0) {
return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
}

return round($number - 0.5 * 0.1 ** $digits + self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_UP);
$result = sprintf("%.{$digitsPlus1}F", $number - 0.5 * 0.1 ** $digits);

return round((float) $result, $digits, PHP_ROUND_HALF_UP);
}

/**
Expand Down
29 changes: 23 additions & 6 deletions src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class Trunc
* TRUNC.
*
* Truncates value to the number of fractional digits by number_digits.
* This will probably not be the precise result in the unlikely
* event that the number of digits to the left of the decimal
* plus the number of digits to the right exceeds PHP_FLOAT_DIG
* (or possibly that value minus 1).
* Excel is unlikely to do any better.
*
* @param array|float $value Or can be an array of values
* @param array|int $digits Or can be an array of values
Expand All @@ -34,15 +39,27 @@ public static function evaluate(array|float|string|null $value = 0, array|int|st
return $e->getMessage();
}

$digits = floor($digits);
if ($value == 0) {
return $value;
}

// Truncate
$adjust = 10 ** $digits;
if ($value >= 0) {
$minusSign = '';
} else {
$minusSign = '-';
$value = -$value;
}
$digits = (int) floor($digits);
if ($digits < 0) {
$result = (float) (substr(sprintf('%.0F', $value), 0, $digits) . str_repeat('0', -$digits));

if (($digits > 0) && (rtrim((string) (int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
return $value;
return ($minusSign === '') ? $result : -$result;
}
$decimals = (floor($value) == (int) $value) ? (PHP_FLOAT_DIG - strlen((string) (int) $value)) : $digits;
$resultString = ($decimals < 0) ? sprintf('%F', $value) : sprintf('%.' . $decimals . 'F', $value);
$regExp = '/([.]\\d{' . $digits . '})\\d+$/';
$result = $minusSign . (preg_replace($regExp, '$1', $resultString) ?? $resultString);

return ((int) ($value * $adjust)) / $adjust;
return (float) $result;
}
}
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Cell/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Cell implements Stringable

/**
* The collection of cells that this cell belongs to (i.e. The Cell Collection for the parent Worksheet).
*
* @var ?Cells
*/
private ?Cells $parent;

Expand Down
1 change: 0 additions & 1 deletion src/PhpSpreadsheet/Chart/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ abstract class Properties

protected bool $objectState = false; // used only for minor gridlines

/** @var ?float */
protected ?float $glowSize = null;

protected ChartColor $glowColor;
Expand Down
3 changes: 0 additions & 3 deletions src/PhpSpreadsheet/Helper/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,10 @@ class Html
'yellowgreen' => '9acd32',
];

/** @var ?string */
private ?string $face = null;

/** @var ?string */
private ?string $size = null;

/** @var ?string */
private ?string $color = null;

private bool $bold = false;
Expand Down
1 change: 0 additions & 1 deletion src/PhpSpreadsheet/Reader/Csv/Delimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Delimiter

protected int $numberLines = 0;

/** @var ?string */
protected ?string $delimiter = null;

/**
Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Reader/Xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ class Xls extends BaseReader

/**
* The current RC4 decryption object.
*
* @var ?Xls\RC4
*/
private ?Xls\RC4 $rc4Key = null;

Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class Styles extends BaseParserClass
{
/**
* Theme instance.
*
* @var ?Theme
*/
private ?Theme $theme = null;

Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class ReferenceHelper

/**
* Instance of this class.
*
* @var ?ReferenceHelper
*/
private static ?ReferenceHelper $instance = null;

Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/RichText/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Run extends TextElement implements ITextElement
{
/**
* Font.
*
* @var ?Font
*/
private ?Font $font;

Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class Settings

/**
* The cache implementation to be used for cell collection.
*
* @var ?CacheInterface
*/
private static ?CacheInterface $cache = null;

Expand Down
4 changes: 0 additions & 4 deletions src/PhpSpreadsheet/Shared/Escher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ class Escher
{
/**
* Drawing Group Container.
*
* @var ?Escher\DggContainer
*/
private ?Escher\DggContainer $dggContainer = null;

/**
* Drawing Container.
*
* @var ?Escher\DgContainer
*/
private ?Escher\DgContainer $dgContainer = null;

Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Shared/Escher/DggContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class DggContainer

/**
* BLIP Store Container.
*
* @var ?DggContainer\BstoreContainer
*/
private ?DggContainer\BstoreContainer $bstoreContainer = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class BSE

/**
* The BLIP (Big Large Image or Picture).
*
* @var ?BSE\Blip
*/
private ?BSE\Blip $blip = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

abstract class WizardAbstract
{
/**
* @var ?Style
*/
protected ?Style $style = null;

protected string $expression;
Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ class Font extends Supervisor

private string $strikeType = '';

/** @var ?ChartColor */
private ?ChartColor $underlineColor = null;

/** @var ?ChartColor */
private ?ChartColor $chartColor = null;
// end of chart title items

Expand Down
18 changes: 9 additions & 9 deletions src/PhpSpreadsheet/Writer/Xlsx/Workbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Workbook extends WriterPart
/**
* Write workbook to XML format.
*
* @param bool $recalcRequired Indicate whether formulas should be recalculated before writing
* @param bool $preCalculateFormulas If true, formulas will be calculated before writing
*
* @return string XML Output
*/
public function writeWorkbook(Spreadsheet $spreadsheet, bool $recalcRequired = false): string
public function writeWorkbook(Spreadsheet $spreadsheet, bool $preCalculateFormulas = false): string
{
// Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) {
Expand Down Expand Up @@ -57,7 +57,7 @@ public function writeWorkbook(Spreadsheet $spreadsheet, bool $recalcRequired = f
(new DefinedNamesWriter($objWriter, $spreadsheet))->write();

// calcPr
$this->writeCalcPr($objWriter, $recalcRequired);
$this->writeCalcPr($objWriter, $preCalculateFormulas);

$objWriter->endElement();

Expand Down Expand Up @@ -146,9 +146,9 @@ private function writeWorkbookProtection(XMLWriter $objWriter, Spreadsheet $spre
/**
* Write calcPr.
*
* @param bool $recalcRequired Indicate whether formulas should be recalculated before writing
* @param bool $preCalculateFormulas If true, formulas will be calculated before writing
*/
private function writeCalcPr(XMLWriter $objWriter, bool $recalcRequired = true): void
private function writeCalcPr(XMLWriter $objWriter, bool $preCalculateFormulas = true): void
{
$objWriter->startElement('calcPr');

Expand All @@ -157,10 +157,10 @@ private function writeCalcPr(XMLWriter $objWriter, bool $recalcRequired = true):
// because the file has changed
$objWriter->writeAttribute('calcId', '999999');
$objWriter->writeAttribute('calcMode', 'auto');
// fullCalcOnLoad isn't needed if we've recalculating for the save
$objWriter->writeAttribute('calcCompleted', ($recalcRequired) ? '1' : '0');
$objWriter->writeAttribute('fullCalcOnLoad', ($recalcRequired) ? '0' : '1');
$objWriter->writeAttribute('forceFullCalc', ($recalcRequired) ? '0' : '1');
// fullCalcOnLoad isn't needed if we will calculate before writing
$objWriter->writeAttribute('calcCompleted', ($preCalculateFormulas) ? '1' : '0');
$objWriter->writeAttribute('fullCalcOnLoad', ($preCalculateFormulas) ? '0' : '1');
$objWriter->writeAttribute('forceFullCalc', ($preCalculateFormulas) ? '0' : '1');

$objWriter->endElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ class SetupTeardownDatabases extends TestCase
{
protected const RESULT_CELL = 'Z1';

/**
* @var ?Spreadsheet
*/
private ?Spreadsheet $spreadsheet = null;

/**
* @var ?Worksheet
*/
private ?Worksheet $sheet = null;

protected function setUp(): void
Expand Down
Loading

0 comments on commit f3ae0bd

Please sign in to comment.