Skip to content

Commit

Permalink
Merge branch 'master' into parseutf8
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Feb 7, 2025
2 parents ac34f58 + 06f0b4c commit d0a0080
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 175 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).

- Data Validations will be stored by worksheet, not cell. Index can be one or more cells or cell ranges. [Issue #797](https://github.com/PHPOffice/PhpSpreadsheet/issues/797) [Issue #4091](https://github.com/PHPOffice/PhpSpreadsheet/issues/4091) [Issue #4206](https://github.com/PHPOffice/PhpSpreadsheet/issues/4206) [PR #4240](https://github.com/PHPOffice/PhpSpreadsheet/pull/4240)
- Conditional Formatting adds Priority property and handles overlapping ranges better. [Issue #4312](https://github.com/PHPOffice/PhpSpreadsheet/issues/4312) [Issue #4318](https://github.com/PHPOffice/PhpSpreadsheet/issues/4318) [PR #4314](https://github.com/PHPOffice/PhpSpreadsheet/pull/4314)
- Csv Reader will no longer auto-detect Mac line endings by default. Prior behavior can be explicitly enabled via `setTestAutoDetect(true)`, and it will not be possible at all with Php9+. [Issue #4092](https://github.com/PHPOffice/PhpSpreadsheet/issues/4092) [PR #4340](https://github.com/PHPOffice/PhpSpreadsheet/pull/4340)
- Html Writer will now use "better boolean" logic. Booleans will now be output by default as TRUE/FALSE rather than 1/null-string. Prior behavior can be explicitly enabled via `setBetterBoolean(false)`. [PR #4340](https://github.com/PHPOffice/PhpSpreadsheet/pull/4340)
- Xlsx Writer will now use false as the default for `forceFullCalc`. This affects writes with `preCalculateFormulas` set to false. Prior behavior can be explicitly enabled via `setForceFullCalc(null)`.[PR #4340](https://github.com/PHPOffice/PhpSpreadsheet/pull/4340)
- Deletion of items deprecated in Release 3. See "removed" below.

### Added
Expand All @@ -19,7 +22,14 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Removed

- Nothing yet.
- Worksheet::getStyles - no replacement. [PR #4330](https://github.com/PHPOffice/PhpSpreadsheet/pull/4330)
- The following items were deprecated in release 3 and are now removed.
- Drawing::setIsUrl - no replacement.
- Settings::setLibXmlLoaderOptions() and Settings::getLibXmlLoaderOptions() - no replacement.
- Worksheet::getHashCode - no replacement.
- IReader::SKIP_EMPTY_CELLS - use its alias IGNORE_EMPTY_CELLS instead.
- Worksheet::getProtectedCells - use getProtectedCellRanges instead.
- Writer/Html::isMpdf property - use instanceof Mpdf instead.

### Changed

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ This makes it easier to see exactly what is being tested when reviewing the PR.
3. Push the tag with `git push --tags`, GitHub Actions will create a GitHub release automatically, and the release details will automatically be sent to packagist.
4. By default, Github removes markdown headings in the Release Notes. You can either edit to restore these, or, probably preferably, change the default comment character on your system - `git config core.commentChar ";"`.

> **Note:** Tagged releases are made from the `master` branch. Only in an emergency should a tagged release be made from the `release` branch. (i.e. cherry-picked hot-fixes.) However, there are 3 branches which have been updated to apply security patches, and those may be tagged if future security updates are needed.
> **Note:** Tagged releases are made from the `master` branch. Only in an emergency should a tagged release be made from the `release` branch. (i.e. cherry-picked hot-fixes.) However, there are 4 branches which have been updated to apply security patches, and those may be tagged if future security updates are needed.
- release1291
- release210
- release222

- release390
5 changes: 4 additions & 1 deletion docs/topics/reading-and-writing-to-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ even if pre-calculated is set to false
```php
$writer->setForceFullCalc(false);
```
In a future release, the property's default may change to `false` and that statement may no longer be required.
Starting with Release 4.0.0, the property's default is changed to `false` and that statement is no longer be required. The property can be set to `null` if the old behavior is needed.

#### Office 2003 compatibility pack

Expand Down Expand Up @@ -594,6 +594,9 @@ You can suppress testing for Mac line endings as follows:
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
$reader->setTestAutoDetect(false);
```
Starting with Release 4.0.0, the property defaults to `false`,
so the statement above is no longer needed. The old behavior
can be enabled by setting the property to `true`.

### \PhpOffice\PhpSpreadsheet\Writer\Csv

Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class Csv extends BaseReader
*/
private static $constructorCallback;

/** Will be changed to false in next major release */
public const DEFAULT_TEST_AUTODETECT = true;
/** Changed from true to false in release 4.0.0 */
public const DEFAULT_TEST_AUTODETECT = false;

/**
* Attempt autodetect line endings (deprecated after PHP8.1)?
Expand Down
5 changes: 0 additions & 5 deletions src/PhpSpreadsheet/Reader/IReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ interface IReader
*/
public const READ_DATA_ONLY = 2;

/**
* @deprecated 3.4.0 use IGNORE_EMPTY_CELLS instead.
*/
public const SKIP_EMPTY_CELLS = self::IGNORE_EMPTY_CELLS;

/**
* Flag used to ignore empty cells when reading.
*
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ protected function adjustMergeCells(Worksheet $worksheet): void
*/
protected function adjustProtectedCells(Worksheet $worksheet, int $numberOfColumns, int $numberOfRows): void
{
$aProtectedCells = $worksheet->getProtectedCells();
$aProtectedCells = $worksheet->getProtectedCellRanges();
($numberOfColumns > 0 || $numberOfRows > 0)
? uksort($aProtectedCells, [self::class, 'cellReverseSort'])
: uksort($aProtectedCells, [self::class, 'cellSort']);
foreach ($aProtectedCells as $cellAddress => $value) {
foreach ($aProtectedCells as $cellAddress => $protectedRange) {
$newReference = $this->updateCellReference($cellAddress);
if ($cellAddress !== $newReference) {
$worksheet->protectCells($newReference, $value, true);
$worksheet->protectCells($newReference, $protectedRange->getPassword(), true);
$worksheet->unprotectCells($cellAddress);
}
}
Expand Down
35 changes: 0 additions & 35 deletions src/PhpSpreadsheet/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class Settings
*/
private static ?string $chartRenderer = null;

/**
* Default options for libxml loader.
*/
private static ?int $libXmlLoaderOptions = null;

/**
* The cache implementation to be used for cell collection.
*/
Expand Down Expand Up @@ -90,36 +85,6 @@ public static function htmlEntityFlags(): int
return ENT_COMPAT;
}

/**
* Set default options for libxml loader.
*
* @param ?int $options Default options for libxml loader
*
* @deprecated 3.5.0 no longer needed
*/
public static function setLibXmlLoaderOptions(?int $options): int
{
if ($options === null) {
$options = defined('LIBXML_DTDLOAD') ? (LIBXML_DTDLOAD | LIBXML_DTDATTR) : 0;
}
self::$libXmlLoaderOptions = $options;

return $options;
}

/**
* Get default options for libxml loader.
* Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
*
* @return int Default options for libxml loader
*
* @deprecated 3.5.0 no longer needed
*/
public static function getLibXmlLoaderOptions(): int
{
return self::$libXmlLoaderOptions ?? (defined('LIBXML_DTDLOAD') ? (LIBXML_DTDLOAD | LIBXML_DTDATTR) : 0);
}

/**
* Sets the implementation of cache that should be used for cell collection.
*/
Expand Down
14 changes: 0 additions & 14 deletions src/PhpSpreadsheet/Worksheet/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,6 @@ public function getIsURL(): bool
return $this->isUrl;
}

/**
* Set isURL.
*
* @return $this
*
* @deprecated 3.7.0 not needed, property is set by setPath
*/
public function setIsURL(bool $isUrl): self
{
$this->isUrl = $isUrl;

return $this;
}

/**
* Get hash code.
*
Expand Down
51 changes: 4 additions & 47 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Worksheet
/**
* Invalid characters in sheet title.
*/
private static array $invalidCharacters = ['*', ':', '/', '\\', '?', '[', ']'];
private const INVALID_CHARACTERS = ['*', ':', '/', '\\', '?', '[', ']'];

/**
* Parent spreadsheet.
Expand Down Expand Up @@ -157,13 +157,6 @@ class Worksheet
*/
private Protection $protection;

/**
* Collection of styles.
*
* @var Style[]
*/
private array $styles = [];

/**
* Conditional styles. Indexed by cell coordinate, e.g. 'A1'.
*/
Expand Down Expand Up @@ -400,7 +393,7 @@ public function getCellCollection(): Cells
*/
public static function getInvalidCharacters(): array
{
return self::$invalidCharacters;
return self::INVALID_CHARACTERS;
}

/**
Expand All @@ -418,7 +411,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
}
// Some of the printable ASCII characters are invalid: * : / \ ? [ ] and first and last characters cannot be a "'"
if (
(str_replace(self::$invalidCharacters, '', $sheetCodeName) !== $sheetCodeName)
(str_replace(self::INVALID_CHARACTERS, '', $sheetCodeName) !== $sheetCodeName)
|| (Shared\StringHelper::substring($sheetCodeName, -1, 1) == '\'')
|| (Shared\StringHelper::substring($sheetCodeName, 0, 1) == '\'')
) {
Expand All @@ -443,7 +436,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
private static function checkSheetTitle(string $sheetTitle): string
{
// Some of the printable ASCII characters are invalid: * : / \ ? [ ]
if (str_replace(self::$invalidCharacters, '', $sheetTitle) !== $sheetTitle) {
if (str_replace(self::INVALID_CHARACTERS, '', $sheetTitle) !== $sheetTitle) {
throw new Exception('Invalid character found in sheet title');
}

Expand Down Expand Up @@ -1393,16 +1386,6 @@ public function getColumnStyle(string $column): ?Style
);
}

/**
* Get styles.
*
* @return Style[]
*/
public function getStyles(): array
{
return $this->styles;
}

/**
* Get style for cell.
*
Expand Down Expand Up @@ -1957,24 +1940,6 @@ public function unprotectCells(AddressRange|CellAddress|int|string|array $range)
return $this;
}

/**
* Get password for protected cells.
*
* @return string[]
*
* @deprecated 2.0.1 use getProtectedCellRanges instead
* @see Worksheet::getProtectedCellRanges()
*/
public function getProtectedCells(): array
{
$array = [];
foreach ($this->protectedCells as $key => $protectedRange) {
$array[$key] = $protectedRange->getPassword();
}

return $array;
}

/**
* Get protected cells.
*
Expand Down Expand Up @@ -3198,14 +3163,6 @@ public function garbageCollect(): static
return $this;
}

/**
* @deprecated 3.5.0 use getHashInt instead.
*/
public function getHashCode(): string
{
return (string) $this->hash;
}

public function getHashInt(): int
{
return $this->hash;
Expand Down
11 changes: 2 additions & 9 deletions src/PhpSpreadsheet/Writer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ class Html extends BaseWriter
*/
protected bool $isPdf = false;

/**
* Is the current writer creating mPDF?
*
* @deprecated 2.0.1 use instanceof Mpdf instead
*/
protected bool $isMPdf = false;

/**
* Generate the Navigation block.
*/
Expand All @@ -143,7 +136,7 @@ class Html extends BaseWriter
/** @var Chart[] */
private $sheetCharts;

private bool $betterBoolean = false;
private bool $betterBoolean = true;

private string $getTrue = 'TRUE';

Expand Down Expand Up @@ -1494,7 +1487,7 @@ private function generateRowWriteCell(
$dataType = $worksheet->getCell($coordinate)->getDataType();
if ($dataType === DataType::TYPE_BOOL) {
$html .= ' data-type="' . DataType::TYPE_BOOL . '"';
} elseif ($dataType === DataType::TYPE_FORMULA && is_bool($worksheet->getCell($coordinate)->getCalculatedValue())) {
} elseif ($dataType === DataType::TYPE_FORMULA && $this->preCalculateFormulas && is_bool($worksheet->getCell($coordinate)->getCalculatedValue())) {
$html .= ' data-type="' . DataType::TYPE_BOOL . '"';
} elseif (is_numeric($cellData) && $worksheet->getCell($coordinate)->getDataType() === DataType::TYPE_STRING) {
$html .= ' data-type="' . DataType::TYPE_STRING . '"';
Expand Down
7 changes: 0 additions & 7 deletions src/PhpSpreadsheet/Writer/Pdf/Mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ class Mpdf extends Pdf
public const SIMULATED_BODY_START = '<!-- simulated body start -->';
private const BODY_TAG = '<body>';

/**
* Is the current writer creating mPDF?
*
* @deprecated 2.0.1 use instanceof Mpdf instead
*/
protected bool $isMPdf = true;

/**
* Gets the implementation of external PDF library that should be used.
*
Expand Down
6 changes: 5 additions & 1 deletion src/PhpSpreadsheet/Writer/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ class Xlsx extends BaseWriter

private bool $useDynamicArray = false;

private ?bool $forceFullCalc = null;
public const DEFAULT_FORCE_FULL_CALC = false;

// Default changed from null in PhpSpreadsheet 4.0.0.
private ?bool $forceFullCalc = self::DEFAULT_FORCE_FULL_CALC;

/**
* Create a new Xlsx Writer.
Expand Down Expand Up @@ -758,6 +761,7 @@ private function determineUseDynamicArrays(): void
* If null, this will be set to the opposite of $preCalculateFormulas.
* It is likely that false is the desired setting, although
* cases have been reported where true is required (issue #456).
* Nevertheless, default is set to false in PhpSpreadsheet 4.0.0.
*/
public function setForceFullCalc(?bool $forceFullCalc): self
{
Expand Down
7 changes: 4 additions & 3 deletions tests/PhpSpreadsheetTests/Reader/Csv/CsvLineEndingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class CsvLineEndingTest extends TestCase
Expand All @@ -22,7 +23,7 @@ protected function tearDown(): void
}
}

#[\PHPUnit\Framework\Attributes\DataProvider('providerEndings')]
#[DataProvider('providerEndings')]
public function testEndings(string $ending): void
{
if ($ending === "\r" && PHP_VERSION_ID >= 90000) {
Expand All @@ -43,14 +44,14 @@ public function testEndings(string $ending): void
$spreadsheet->disconnectWorksheets();
}

#[\PHPUnit\Framework\Attributes\DataProvider('providerEndings')]
#[DataProvider('providerEndings')]
public function testEndingsNoDetect(string $ending): void
{
$this->tempFile = $filename = File::temporaryFilename();
$data = ['123', '456', '789'];
file_put_contents($filename, implode($ending, $data));
$reader = new Csv();
$reader->setTestAutoDetect(false);
self::assertSame(self::$alwaysFalse, Csv::DEFAULT_TEST_AUTODETECT);
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
if ($ending === "\r") {
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4248Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testHtml(): void
. ' <td class="column0 style0">&nbsp;</td>'
. ' <td class="column1 style28 null"></td>'
. ' <td class="column2 style35 s">Eligible </td>'
. ' <td class="column3 style70 f">Non</td>';
. ' <td class="column3 style70 s">Non</td>';
self::assertStringContainsString($expected, $data, 'Cell D18 style');
$expected = ' td.style70, th.style70 { vertical-align:middle; text-align:center; border-bottom:1px solid #000000 !important; border-top:2px solid #000000 !important; border-left:2px solid #000000 !important; border-right:1px solid #000000 !important; font-weight:bold; color:#000000; font-family:\'Calibri\'; font-size:16pt; background-color:#BDD7EE }';
self::assertStringContainsString($expected, $data, 'background color');
Expand Down
Loading

0 comments on commit d0a0080

Please sign in to comment.