Skip to content

Commit 1a187d6

Browse files
authored
Merge branch 'master' into condxls
2 parents 5763de4 + f2a934a commit 1a187d6

File tree

8 files changed

+241
-79
lines changed

8 files changed

+241
-79
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com)
66
and this project adheres to [Semantic Versioning](https://semver.org).
77

8+
## TBD - 2.2.0
9+
10+
### Added
11+
12+
- Nothing
13+
14+
### Changed
15+
16+
- Nothing
17+
18+
### Deprecated
19+
20+
- Nothing
21+
22+
### Moved
23+
24+
- Nothing
25+
26+
### Fixed
27+
28+
- Incorrect Reader CSV with BOM. [Issue #4028](https://github.com/PHPOffice/PhpSpreadsheet/issues/4028) [PR #4029](https://github.com/PHPOffice/PhpSpreadsheet/pull/4029)
29+
- POWER Null/Bool Args. [PR #4031](https://github.com/PHPOffice/PhpSpreadsheet/pull/4031)
30+
831
## 2024-05-11 - 2.1.0
932

1033
### MINOR BREAKING CHANGE

src/PhpSpreadsheet/Calculation/MathTrig/Operations.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public static function mod(mixed $dividend, mixed $divisor): array|string|float
5252
*
5353
* Computes x raised to the power y.
5454
*
55-
* @param array|float|int|string $x Or can be an array of values
56-
* @param array|float|int|string $y Or can be an array of values
55+
* @param null|array|bool|float|int|string $x Or can be an array of values
56+
* @param null|array|bool|float|int|string $y Or can be an array of values
5757
*
5858
* @return array|float|int|string The result, or a string containing an error
5959
* If an array of numbers is passed as an argument, then the returned result will also be an array
6060
* with the same dimensions
6161
*/
62-
public static function power(array|float|int|string $x, array|float|int|string $y): array|float|int|string
62+
public static function power(null|array|bool|float|int|string $x, null|array|bool|float|int|string $y): array|float|int|string
6363
{
6464
if (is_array($x) || is_array($y)) {
6565
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $y);

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ public function canRead(string $filename): bool
147147
return false;
148148
}
149149

150-
$beginning = $this->readBeginning();
151-
if (preg_match(self::STARTS_WITH_BOM, $beginning)) {
152-
return true;
153-
}
150+
$beginning = preg_replace(self::STARTS_WITH_BOM, '', $this->readBeginning()) ?? '';
151+
154152
$startWithTag = self::startsWithTag($beginning);
155153
$containsTags = self::containsTags($beginning);
156154
$endsWithTag = self::endsWithTag($this->readEnding());

src/PhpSpreadsheet/Writer/Xls/Worksheet.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,7 @@ private function writeCFRule(
28002800

28012801
// $flags : Option flags
28022802
// Alignment
2803-
$bAlignHz = ($conditional->getStyle()->getAlignment()->getHorizontal() === null ? 1 : 0);
2803+
/*$bAlignHz = ($conditional->getStyle()->getAlignment()->getHorizontal() === null ? 1 : 0);
28042804
$bAlignVt = ($conditional->getStyle()->getAlignment()->getVertical() === null ? 1 : 0);
28052805
$bAlignWrapTx = ($conditional->getStyle()->getAlignment()->getWrapText() === false ? 1 : 0);
28062806
$bTxRotation = ($conditional->getStyle()->getAlignment()->getTextRotation() === null ? 1 : 0);
@@ -2810,15 +2810,15 @@ private function writeCFRule(
28102810
$bFormatAlign = 1;
28112811
} else {
28122812
$bFormatAlign = 0;
2813-
}
2813+
}*/
28142814
// Protection
2815-
$bProtLocked = ($conditional->getStyle()->getProtection()->getLocked() === null ? 1 : 0);
2815+
/*$bProtLocked = ($conditional->getStyle()->getProtection()->getLocked() === null ? 1 : 0);
28162816
$bProtHidden = ($conditional->getStyle()->getProtection()->getHidden() === null ? 1 : 0);
28172817
if ($bProtLocked == 0 || $bProtHidden == 0) {
28182818
$bFormatProt = 1;
28192819
} else {
28202820
$bFormatProt = 0;
2821-
}
2821+
}*/
28222822
// Border
28232823
$bBorderLeft = ($conditional->getStyle()->getBorders()->getLeft()->getBorderStyle() !== Border::BORDER_OMIT) ? 1 : 0;
28242824
$bBorderRight = ($conditional->getStyle()->getBorders()->getRight()->getBorderStyle() !== Border::BORDER_OMIT) ? 1 : 0;
@@ -2856,19 +2856,19 @@ private function writeCFRule(
28562856
}
28572857
// Alignment
28582858
$flags = 0;
2859-
$flags |= (1 == $bAlignHz ? 0x00000001 : 0);
2860-
$flags |= (1 == $bAlignVt ? 0x00000002 : 0);
2861-
$flags |= (1 == $bAlignWrapTx ? 0x00000004 : 0);
2862-
$flags |= (1 == $bTxRotation ? 0x00000008 : 0);
2859+
//$flags |= (1 == $bAlignHz ? 0x00000001 : 0);
2860+
//$flags |= (1 == $bAlignVt ? 0x00000002 : 0);
2861+
//$flags |= (1 == $bAlignWrapTx ? 0x00000004 : 0);
2862+
//$flags |= (1 == $bTxRotation ? 0x00000008 : 0);
28632863
// Justify last line flag
28642864
$flags |= (1 == self::$always1 ? 0x00000010 : 0);
2865-
$flags |= (1 == $bIndent ? 0x00000020 : 0);
2866-
$flags |= (1 == $bShrinkToFit ? 0x00000040 : 0);
2865+
//$flags |= (1 == $bIndent ? 0x00000020 : 0);
2866+
//$flags |= (1 == $bShrinkToFit ? 0x00000040 : 0);
28672867
// Default
28682868
$flags |= (1 == self::$always1 ? 0x00000080 : 0);
28692869
// Protection
2870-
$flags |= (1 == $bProtLocked ? 0x00000100 : 0);
2871-
$flags |= (1 == $bProtHidden ? 0x00000200 : 0);
2870+
//$flags |= (1 == $bProtLocked ? 0x00000100 : 0);
2871+
//$flags |= (1 == $bProtHidden ? 0x00000200 : 0);
28722872
// Border
28732873
$flags |= (1 == $bBorderLeft ? 0x00000400 : 0);
28742874
$flags |= (1 == $bBorderRight ? 0x00000800 : 0);
@@ -2884,18 +2884,18 @@ private function writeCFRule(
28842884
// Font
28852885
$flags |= (1 == $bFormatFont ? 0x04000000 : 0);
28862886
// Alignment:
2887-
$flags |= (1 == $bFormatAlign ? 0x08000000 : 0);
2887+
//$flags |= (1 == $bFormatAlign ? 0x08000000 : 0);
28882888
// Border
28892889
$flags |= (1 == $bFormatBorder ? 0x10000000 : 0);
28902890
// Pattern
28912891
$flags |= (1 == $bFormatFill ? 0x20000000 : 0);
28922892
// Protection
2893-
$flags |= (1 == $bFormatProt ? 0x40000000 : 0);
2893+
//$flags |= (1 == $bFormatProt ? 0x40000000 : 0);
28942894
// Text direction
28952895
$flags |= (1 == self::$always0 ? 0x80000000 : 0);
28962896

28972897
$dataBlockFont = null;
2898-
$dataBlockAlign = null;
2898+
//$dataBlockAlign = null;
28992899
$dataBlockBorder = null;
29002900
$dataBlockFill = null;
29012901

@@ -2995,7 +2995,7 @@ private function writeCFRule(
29952995
// Always
29962996
$dataBlockFont .= pack('v', 0x0001);
29972997
}
2998-
if ($bFormatAlign === 1) {
2998+
/*if ($bFormatAlign === 1) {
29992999
// Alignment and text break
30003000
$blockAlign = Style\CellAlignment::horizontal($conditional->getStyle()->getAlignment());
30013001
$blockAlign |= Style\CellAlignment::wrap($conditional->getStyle()->getAlignment()) << 3;
@@ -3018,7 +3018,7 @@ private function writeCFRule(
30183018
$blockIndentRelative = 255;
30193019
30203020
$dataBlockAlign = pack('CCvvv', $blockAlign, $blockRotation, $blockIndent, $blockIndentRelative, 0x0000);
3021-
}
3021+
}*/
30223022
if ($bFormatBorder === 1) {
30233023
$blockLineStyle = Style\CellBorder::style($conditional->getStyle()->getBorders()->getLeft());
30243024
$blockLineStyle |= Style\CellBorder::style($conditional->getStyle()->getBorders()->getRight()) << 4;
@@ -3052,18 +3052,18 @@ private function writeCFRule(
30523052
if ($bFormatFont === 1) { // Block Formatting : OK
30533053
$data .= $dataBlockFont;
30543054
}
3055-
if ($bFormatAlign === 1) {
3056-
$data .= $dataBlockAlign;
3057-
}
3055+
//if ($bFormatAlign === 1) {
3056+
// $data .= $dataBlockAlign;
3057+
//}
30583058
if ($bFormatBorder === 1) {
30593059
$data .= $dataBlockBorder;
30603060
}
30613061
if ($bFormatFill === 1) { // Block Formatting : OK
30623062
$data .= $dataBlockFill;
30633063
}
3064-
if ($bFormatProt == 1) {
3065-
$data .= $this->getDataBlockProtection($conditional);
3066-
}
3064+
//if ($bFormatProt == 1) {
3065+
// $data .= $this->getDataBlockProtection($conditional);
3066+
//}
30673067
if ($operand1 !== null) {
30683068
$data .= $operand1;
30693069
}
@@ -3127,7 +3127,7 @@ private function writeCFHeader(string $cellCoordinate, array $conditionalStyles)
31273127
return true;
31283128
}
31293129

3130-
private function getDataBlockProtection(Conditional $conditional): int
3130+
/*private function getDataBlockProtection(Conditional $conditional): int
31313131
{
31323132
$dataBlockProtection = 0;
31333133
if ($conditional->getStyle()->getProtection()->getLocked() == Protection::PROTECTION_PROTECTED) {
@@ -3138,7 +3138,7 @@ private function getDataBlockProtection(Conditional $conditional): int
31383138
}
31393139
31403140
return $dataBlockProtection;
3141-
}
3141+
}*/
31423142

31433143
private function workbookColorIndex(?string $rgb, int $default): int
31443144
{

src/PhpSpreadsheet/Writer/Xlsx/Style.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -506,56 +506,9 @@ private function writeCellStyleDxf(XMLWriter $objWriter, \PhpOffice\PhpSpreadshe
506506
// fill
507507
$this->writeFill($objWriter, $style->getFill());
508508

509-
// alignment
510-
$horizontal = Alignment::HORIZONTAL_ALIGNMENT_FOR_XLSX[$style->getAlignment()->getHorizontal()] ?? '';
511-
$vertical = Alignment::VERTICAL_ALIGNMENT_FOR_XLSX[$style->getAlignment()->getVertical()] ?? '';
512-
$rotation = $style->getAlignment()->getTextRotation();
513-
if ($horizontal || $vertical || $rotation !== null) {
514-
$objWriter->startElement('alignment');
515-
if ($horizontal) {
516-
$objWriter->writeAttribute('horizontal', $horizontal);
517-
}
518-
if ($vertical) {
519-
$objWriter->writeAttribute('vertical', $vertical);
520-
}
521-
522-
if ($rotation !== null) {
523-
if ($rotation >= 0) {
524-
$textRotation = $rotation;
525-
} else {
526-
$textRotation = 90 - $rotation;
527-
}
528-
$objWriter->writeAttribute('textRotation', (string) $textRotation);
529-
}
530-
$objWriter->endElement();
531-
}
532-
533509
// border
534510
$this->writeBorder($objWriter, $style->getBorders());
535511

536-
// protection
537-
if ((!empty($style->getProtection()->getLocked())) || (!empty($style->getProtection()->getHidden()))) {
538-
if (
539-
$style->getProtection()->getLocked() !== Protection::PROTECTION_INHERIT
540-
|| $style->getProtection()->getHidden() !== Protection::PROTECTION_INHERIT
541-
) {
542-
$objWriter->startElement('protection');
543-
if (
544-
($style->getProtection()->getLocked() !== null)
545-
&& ($style->getProtection()->getLocked() !== Protection::PROTECTION_INHERIT)
546-
) {
547-
$objWriter->writeAttribute('locked', ($style->getProtection()->getLocked() == Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
548-
}
549-
if (
550-
($style->getProtection()->getHidden() !== null)
551-
&& ($style->getProtection()->getHidden() !== Protection::PROTECTION_INHERIT)
552-
) {
553-
$objWriter->writeAttribute('hidden', ($style->getProtection()->getHidden() == Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
554-
}
555-
$objWriter->endElement();
556-
}
557-
}
558-
559512
$objWriter->endElement();
560513
}
561514

tests/PhpSpreadsheetTests/IOFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public static function providerIdentify(): array
102102
// Following not readable by Excel.
103103
//['samples/templates/Excel2003XMLTest.xml', 'Xml', Reader\Xml::class],
104104
['samples/templates/46readHtml.html', 'Html', Reader\Html::class],
105+
['tests/data/Reader/CSV/encoding.utf8bom.csv', 'Csv', Reader\Csv::class],
105106
];
106107
}
107108

0 commit comments

Comments
 (0)