Skip to content

Commit

Permalink
Merge branch 'master' into pr1449
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Dec 27, 2024
2 parents 727f06e + 2297dba commit ff405d6
Show file tree
Hide file tree
Showing 44 changed files with 637 additions and 211 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install locales
run: sudo apt-get install -y language-pack-fr language-pack-de

- name: Install single-byte locale
run: sudo sed -i -e 's/# de_DE@euro/de_DE@euro/g' /etc/locale.gen && sudo locale-gen de_DE@euro

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
Expand Down
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com)
and this project adheres to [Semantic Versioning](https://semver.org).

## TBD - 3.7.0
## TBD - 3.8.0

### Added

Expand All @@ -27,6 +27,22 @@ and this project adheres to [Semantic Versioning](https://semver.org).

- Nothing yet.

## 2024-12-26 - 3.7.0

### Deprecated

- Drawing::setIsUrl is unneeded. The property is set when setPath determines whether path is a url.

### Fixed

- Security patches for Samples.
- Security patches for Html Writer.
- Avoid unexpected charset in currency symbol. [PR #4279](https://github.com/PHPOffice/PhpSpreadsheet/pull/4279)
- Add forceFullCalc option to Xlsx Writer. [Issue #4269](https://github.com/PHPOffice/PhpSpreadsheet/issues/4269) [PR #4271](https://github.com/PHPOffice/PhpSpreadsheet/pull/4271)
- More context options may be needed for http(s) image. [Php issue 17121](https://github.com/php/php-src/issues/17121) [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
- Coverage-related tweaks to Xls Reader. [PR #4277](https://github.com/PHPOffice/PhpSpreadsheet/pull/4277)
- Several fixed to ODS Writer. [Issue #4261](https://github.com/PHPOffice/PhpSpreadsheet/issues/4261) [PR #4263](https://github.com/PHPOffice/PhpSpreadsheet/pull/4263) [PR #4264](https://github.com/PHPOffice/PhpSpreadsheet/pull/4264) [PR #4266](https://github.com/PHPOffice/PhpSpreadsheet/pull/4266)

## 2024-12-08 - 3.6.0

### Added
Expand Down
6 changes: 6 additions & 0 deletions docs/topics/reading-and-writing-to-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ $writer->save("05featuredemo.xlsx");
**Note** Formulas will still be calculated in any column set to be autosized
even if pre-calculated is set to false

**Note** Prior to release 3.7.0, the use of this feature will cause Excel to be used in a mode where opening a sheet saved in this manner *might* not automatically recalculate a cell's formula when a cell used it the formula changes. Furthermore, that behavior might be applied to all spreadsheets open at the time. To avoid this behavior, add the following statement after `setPreCalculateFormulas` above:
```php
$writer->setForceFullCalc(false);
```
In a future release, the property's default may change to `false` and that statement may no longer be required.

#### Office 2003 compatibility pack

Because of a bug in the Office2003 compatibility pack, there can be some
Expand Down
10 changes: 6 additions & 4 deletions samples/Engineering/Convert-Online.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@
$quantity = $_POST['quantity'];
$fromUnit = $_POST['fromUnit'];
$toUnit = $_POST['toUnit'];
if (isset($units[$_POST['category']][$fromUnit], $units[$_POST['category']][$toUnit])) {
if (!is_numeric($quantity)) {
$helper->log('Quantity is not numeric');
} elseif (isset($units[$_POST['category']][$fromUnit], $units[$_POST['category']][$toUnit])) {
/** @var float|string */
$result = ConvertUOM::CONVERT($quantity, $fromUnit, $toUnit);

echo "{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}", PHP_EOL;
$helper->log("{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}");
} else {
echo 'Please enter quantity and select From Unit and To Unit', PHP_EOL;
$helper->log('Please enter quantity and select From Unit and To Unit');
}
} else {
echo 'Please enter quantity and select From Unit and To Unit', PHP_EOL;
$helper->log('Please enter quantity and select From Unit and To Unit');
}
19 changes: 7 additions & 12 deletions samples/Wizards/NumberFormat/Accounting.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@
<input name="position" type="radio" value="0" <?php echo (isset($_POST['position']) && $_POST['position'] === '0') ? 'checked' : ''; ?>>Trailing
</div>
</div>
<div class="mb-3 row">
<label for="spacing" class="col-sm-2 col-form-label">Currency Spacing</label>
<div class="col-sm-10">
<input name="spacing" type="radio" value="1" <?php echo (isset($_POST['spacing']) && $_POST['spacing'] === '1') ? 'checked' : ''; ?>>Yes
<input name="spacing" type="radio" value="0" <?php echo ((isset($_POST['spacing']) === false) || (isset($_POST['spacing']) && $_POST['spacing'] === '0')) ? 'checked' : ''; ?>>No
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-10">
<input class="btn btn-primary" name="submit" type="submit" value="Display Mask"><br />
Expand All @@ -85,21 +78,23 @@
$helper->log('The Sample Number Value must be numeric');
} elseif (!is_numeric($_POST['decimals']) || str_contains((string) $_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
$helper->log('The Decimal Places value must be positive integer');
} elseif (!in_array($_POST['currency'], array_keys($currencies), true)) {
$helper->log('Unrecognized currency symbol');
} else {
try {
$wizard = new Wizard\Accounting($_POST['currency'], (int) $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position'], (bool) $_POST['spacing']);
$wizard = new Wizard\Accounting($_POST['currency'], (int) $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position']);
$mask = $wizard->format();
$example = (string) NumberFormat::toFormattedString((float) $_POST['number'], $mask);
$helper->log('<hr /><b>Code:</b><br />');
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
$helper->log(
"\$mask = Wizard\\Accounting('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
"\$wizard = new Wizard\\Accounting('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
. (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR')
. ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL')
. ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING')
. ');<br />'
. ');'
);
$helper->log('echo (string) $mask;');
$helper->log('$mask = $wizard->format();');
$helper->log('<br />echo (string) $mask;');
$helper->log('<hr /><b>Mask:</b><br />');
$helper->log($mask . '<br />');
$helper->log('<br /><b>Example:</b><br />');
Expand Down
41 changes: 32 additions & 9 deletions samples/Wizards/NumberFormat/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard\CurrencyNegative;
use PhpOffice\PhpSpreadsheet\Writer\Html as HtmlWriter;

require __DIR__ . '/../Header.php';

Expand All @@ -15,6 +17,19 @@
return;
}

$negatives = [
CurrencyNegative::minus,
CurrencyNegative::redMinus,
CurrencyNegative::parentheses,
CurrencyNegative::redParentheses,
];
$negativesString = [
'CurrencyNegative::minus',
'CurrencyNegative::redMinus',
'CurrencyNegative::parentheses',
'CurrencyNegative::redParentheses',
];

$currencies = [
'$' => 'US Dollars ($)',
'' => 'Euro (€)',
Expand Down Expand Up @@ -65,10 +80,12 @@
</div>
</div>
<div class="mb-3 row">
<label for="spacing" class="col-sm-2 col-form-label">Currency Spacing</label>
<label for="negative" class="col-sm-2 col-form-label">Negative Numbers</label>
<div class="col-sm-10">
<input name="spacing" type="radio" value="1" <?php echo (isset($_POST['spacing']) && $_POST['spacing'] === '1') ? 'checked' : ''; ?>>Yes
<input name="spacing" type="radio" value="0" <?php echo ((isset($_POST['spacing']) === false) || (isset($_POST['spacing']) && $_POST['spacing'] === '0')) ? 'checked' : ''; ?>>No
<input name="negative" type="radio" value="0" <?php echo (!isset($_POST['negative']) || $_POST['negative'] === '0') ? 'checked' : ''; ?>>Minus Sign
<input name="negative" type="radio" value="1" <?php echo (isset($_POST['negative']) && $_POST['negative'] === '1') ? 'checked' : ''; ?>>Red Minus Sign
<input name="negative" type="radio" value="2" <?php echo (isset($_POST['negative']) && $_POST['negative'] === '2') ? 'checked' : ''; ?>>Parentheses
<input name="negative" type="radio" value="3" <?php echo (isset($_POST['negative']) && $_POST['negative'] === '3') ? 'checked' : ''; ?>>Red Parentheses
</div>
</div>
<div class="mb-3 row">
Expand All @@ -85,21 +102,27 @@
$helper->log('The Sample Number Value must be numeric');
} elseif (!is_numeric($_POST['decimals']) || str_contains((string) $_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
$helper->log('The Decimal Places value must be positive integer');
} elseif (!in_array($_POST['currency'], array_keys($currencies), true)) {
$helper->log('Unrecognized currency symbol');
} else {
try {
$wizard = new Wizard\Currency($_POST['currency'], (int) $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position'], (bool) $_POST['spacing']);
$negative = $negatives[$_POST['negative']] ?? CurrencyNegative::minus;
$wizard = new Wizard\Currency($_POST['currency'], (int) $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position']);
$wizard->setNegative($negative);
$mask = $wizard->format();
$example = (string) NumberFormat::toFormattedString((float) $_POST['number'], $mask);
$example = (string) NumberFormat::toFormattedString((float) $_POST['number'], $mask, [HtmlWriter::class, 'formatColorStatic']);
$helper->log('<hr /><b>Code:</b><br />');
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\CurrencyNegative;');
$helper->log(
"\$mask = Wizard\\Currency('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
"\$wizard = new Wizard\\Currency('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
. (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR')
. ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL')
. ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING')
. ');<br />'
. ');'
);
$helper->log('echo (string) $mask;');
$helper->log('$wizard->setNegative(' . $negativesString[$_POST['negative']] . ');');
$helper->log('$mask = $wizard->format();');
$helper->log('<br />echo (string) $mask;');
$helper->log('<hr /><b>Mask:</b><br />');
$helper->log($mask . '<br />');
$helper->log('<br /><b>Example:</b><br />');
Expand Down
5 changes: 5 additions & 0 deletions src/PhpSpreadsheet/Collection/Memory/SimpleCache1.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*
* Alternative implementation should leverage off-memory, non-volatile storage
* to reduce overall memory usage.
*
* Either SimpleCache1 or SimpleCache3, but not both, may be used.
* For code coverage testing, it will always be SimpleCache3.
*
* @codeCoverageIgnore
*/
class SimpleCache1 implements CacheInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Helper/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ class Downloader
public function __construct(string $folder, string $filename, ?string $filetype = null)
{
if ((is_dir($folder) === false) || (is_readable($folder) === false)) {
throw new Exception("Folder {$folder} is not accessable");
throw new Exception('Folder is not accessible');
}
$filepath = "{$folder}/{$filename}";
$this->filepath = (string) realpath($filepath);
$this->filename = basename($filepath);
if ((file_exists($this->filepath) === false) || (is_readable($this->filepath) === false)) {
throw new Exception("{$this->filename} not found, or cannot be read");
throw new Exception('File not found, or cannot be read');
}

$filetype ??= pathinfo($filename, PATHINFO_EXTENSION);
if (array_key_exists(strtolower($filetype), self::CONTENT_TYPES) === false) {
throw new Exception("Invalid filetype: {$filetype} cannot be downloaded");
throw new Exception('Invalid filetype: file cannot be downloaded');
}
$this->filetype = strtolower($filetype);
}
Expand Down
8 changes: 1 addition & 7 deletions src/PhpSpreadsheet/Reader/Xls/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ public static function map(int $color, array $palette, int $version): array
return $palette[$color - 8];
}

// default color table
if ($version == Xls::XLS_BIFF8) {
return Color\BIFF8::lookup($color);
}

// BIFF5
return Color\BIFF5::lookup($color);
return ($version === Xls::XLS_BIFF8) ? Color\BIFF8::lookup($color) : Color\BIFF5::lookup($color);
}
}
12 changes: 2 additions & 10 deletions src/PhpSpreadsheet/Reader/Xls/ConditionalFormatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,12 @@ class ConditionalFormatting extends Xls

public static function type(int $type): ?string
{
if (isset(self::$types[$type])) {
return self::$types[$type];
}

return null;
return self::$types[$type] ?? null;
}

public static function operator(int $operator): ?string
{
if (isset(self::$operators[$operator])) {
return self::$operators[$operator];
}

return null;
return self::$operators[$operator] ?? null;
}

/**
Expand Down
18 changes: 3 additions & 15 deletions src/PhpSpreadsheet/Reader/Xls/DataValidationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,17 @@ class DataValidationHelper extends Xls

public static function type(int $type): ?string
{
if (isset(self::$types[$type])) {
return self::$types[$type];
}

return null;
return self::$types[$type] ?? null;
}

public static function errorStyle(int $errorStyle): ?string
{
if (isset(self::$errorStyles[$errorStyle])) {
return self::$errorStyles[$errorStyle];
}

return null;
return self::$errorStyles[$errorStyle] ?? null;
}

public static function operator(int $operator): ?string
{
if (isset(self::$operators[$operator])) {
return self::$operators[$operator];
}

return null;
return self::$operators[$operator] ?? null;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/PhpSpreadsheet/Reader/Xls/ListFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ protected function listWorksheetNames2(string $filename, Xls $xls): array
}

foreach ($xls->sheets as $sheet) {
if ($sheet['sheetType'] != 0x00) {
if ($sheet['sheetType'] === 0x00) {
// 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
continue;
$worksheetNames[] = $sheet['name'];
}

$worksheetNames[] = $sheet['name'];
}

return $worksheetNames;
Expand Down Expand Up @@ -93,7 +91,7 @@ protected function listWorksheetInfo2(string $filename, Xls $xls): array

// Parse the individual sheets
foreach ($xls->sheets as $sheet) {
if ($sheet['sheetType'] != 0x00) {
if ($sheet['sheetType'] !== 0x00) {
// 0x00: Worksheet
// 0x02: Chart
// 0x06: Visual Basic module
Expand Down
6 changes: 1 addition & 5 deletions src/PhpSpreadsheet/Reader/Xls/Style/Border.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class Border

public static function lookup(int $index): string
{
if (isset(self::$borderStyleMap[$index])) {
return self::$borderStyleMap[$index];
}

return StyleBorder::BORDER_NONE;
return self::$borderStyleMap[$index] ?? StyleBorder::BORDER_NONE;
}
}
6 changes: 1 addition & 5 deletions src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class FillPattern
*/
public static function lookup(int $index): string
{
if (isset(self::$fillPatternMap[$index])) {
return self::$fillPatternMap[$index];
}

return Fill::FILL_NONE;
return self::$fillPatternMap[$index] ?? Fill::FILL_NONE;
}
}
Loading

0 comments on commit ff405d6

Please sign in to comment.