Skip to content

Commit f0f0a33

Browse files
authored
Merge branch 'master' into updatechglog
2 parents fca1a6e + fb51c3d commit f0f0a33

File tree

14 files changed

+179
-10
lines changed

14 files changed

+179
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a
4646
- Maximum column width. [PR #4581](https://github.com/PHPOffice/PhpSpreadsheet/pull/4581)
4747
- PrintArea after row/column delete. [Issue #2912](https://github.com/PHPOffice/PhpSpreadsheet/issues/2912) [PR #4598](https://github.com/PHPOffice/PhpSpreadsheet/pull/4598)
4848
- Remove deprecated imagedestroy call. [PR #4625](https://github.com/PHPOffice/PhpSpreadsheet/pull/4625)
49+
- Excel 2007 problem with newlines. [Issue #4619](https://github.com/PHPOffice/PhpSpreadsheet/issues/4619) [PR #4620](https://github.com/PHPOffice/PhpSpreadsheet/pull/4620)
50+
- Compatibility changes for Php 8.5. [PR #4601](https://github.com/PHPOffice/PhpSpreadsheet/pull/4601) [PR #4611](https://github.com/PHPOffice/PhpSpreadsheet/pull/4611)
4951

5052
## 2025-08-10 - 5.0.0
5153

src/PhpSpreadsheet/Reader/BaseReader.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ abstract class BaseReader implements IReader
5454
*/
5555
protected bool $allowExternalImages = false;
5656

57+
/**
58+
* Create a blank sheet if none are read,
59+
* possibly due to a typo when using LoadSheetsOnly.
60+
*/
61+
protected bool $createBlankSheetIfNoneRead = false;
62+
5763
/**
5864
* IReadFilter instance.
5965
*/
@@ -173,6 +179,17 @@ public function getAllowExternalImages(): bool
173179
return $this->allowExternalImages;
174180
}
175181

182+
/**
183+
* Create a blank sheet if none are read,
184+
* possibly due to a typo when using LoadSheetsOnly.
185+
*/
186+
public function setCreateBlankSheetIfNoneRead(bool $createBlankSheetIfNoneRead): self
187+
{
188+
$this->createBlankSheetIfNoneRead = $createBlankSheetIfNoneRead;
189+
190+
return $this;
191+
}
192+
176193
public function getSecurityScanner(): ?XmlScanner
177194
{
178195
return $this->securityScanner;
@@ -207,6 +224,9 @@ protected function processFlags(int $flags): void
207224
if (((bool) ($flags & self::DONT_ALLOW_EXTERNAL_IMAGES)) === true) {
208225
$this->setAllowExternalImages(false);
209226
}
227+
if (((bool) ($flags & self::CREATE_BLANK_SHEET_IF_NONE_READ)) === true) {
228+
$this->setCreateBlankSheetIfNoneRead(true);
229+
}
210230
}
211231

212232
protected function loadSpreadsheetFromFile(string $filename): Spreadsheet

src/PhpSpreadsheet/Reader/Gnumeric.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
269269
(new Properties($this->spreadsheet))->readProperties($xml, $gnmXML);
270270

271271
$worksheetID = 0;
272+
$sheetCreated = false;
272273
foreach ($gnmXML->Sheets->Sheet as $sheetOrNull) {
273274
$sheet = self::testSimpleXml($sheetOrNull);
274275
$worksheetName = (string) $sheet->Name;
@@ -280,6 +281,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
280281

281282
// Create new Worksheet
282283
$this->spreadsheet->createSheet();
284+
$sheetCreated = true;
283285
$this->spreadsheet->setActiveSheetIndex($worksheetID);
284286
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
285287
// cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
@@ -329,6 +331,9 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
329331
$this->setSelectedCells($sheet);
330332
++$worksheetID;
331333
}
334+
if ($this->createBlankSheetIfNoneRead && !$sheetCreated) {
335+
$this->spreadsheet->createSheet();
336+
}
332337

333338
$this->processDefinedNames($gnmXML);
334339

src/PhpSpreadsheet/Reader/IReader.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ interface IReader
4141
public const ALLOW_EXTERNAL_IMAGES = 16;
4242
public const DONT_ALLOW_EXTERNAL_IMAGES = 32;
4343

44+
public const CREATE_BLANK_SHEET_IF_NONE_READ = 64;
45+
4446
public function __construct();
4547

4648
/**
@@ -149,6 +151,12 @@ public function setAllowExternalImages(bool $allowExternalImages): self;
149151

150152
public function getAllowExternalImages(): bool;
151153

154+
/**
155+
* Create a blank sheet if none are read,
156+
* possibly due to a typo when using LoadSheetsOnly.
157+
*/
158+
public function setCreateBlankSheetIfNoneRead(bool $createBlankSheetIfNoneRead): self;
159+
152160
/**
153161
* Loads PhpSpreadsheet from file.
154162
*
@@ -161,6 +169,7 @@ public function getAllowExternalImages(): bool;
161169
* self::IGNORE_ROWS_WITH_NO_CELLS Don't load any rows that contain no cells.
162170
* self::ALLOW_EXTERNAL_IMAGES Attempt to fetch images stored outside the spreadsheet.
163171
* self::DONT_ALLOW_EXTERNAL_IMAGES Don't attempt to fetch images stored outside the spreadsheet.
172+
* self::CREATE_BLANK_SHEET_IF_NONE_READ If no sheets are read, create a blank one.
164173
*/
165174
public function load(string $filename, int $flags = 0): Spreadsheet;
166175
}

src/PhpSpreadsheet/Reader/Ods.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
318318
$tables = $workbookData->getElementsByTagNameNS($tableNs, 'table');
319319

320320
$worksheetID = 0;
321+
$sheetCreated = false;
321322
foreach ($tables as $worksheetDataSet) {
322323
/** @var DOMElement $worksheetDataSet */
323324
$worksheetName = $worksheetDataSet->getAttributeNS($tableNs, 'name');
@@ -335,6 +336,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
335336

336337
// Create sheet
337338
$spreadsheet->createSheet();
339+
$sheetCreated = true;
338340
$spreadsheet->setActiveSheetIndex($worksheetID);
339341

340342
if ($worksheetName || is_numeric($worksheetName)) {
@@ -441,6 +443,9 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
441443
);
442444
++$worksheetID;
443445
}
446+
if ($this->createBlankSheetIfNoneRead && !$sheetCreated) {
447+
$spreadsheet->createSheet();
448+
}
444449

445450
$autoFilterReader->read($workbookData);
446451
$definedNameReader->read($workbookData);

src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ protected function loadSpreadsheetFromFile2(string $filename, Xls $xls): Spreads
153153

154154
// Parse the individual sheets
155155
$xls->activeSheetSet = false;
156+
$sheetCreated = false;
156157
foreach ($xls->sheets as $sheet) {
157158
$selectedCells = '';
158159
if ($sheet['sheetType'] != 0x00) {
@@ -167,6 +168,7 @@ protected function loadSpreadsheetFromFile2(string $filename, Xls $xls): Spreads
167168

168169
// add sheet to PhpSpreadsheet object
169170
$xls->phpSheet = $xls->spreadsheet->createSheet();
171+
$sheetCreated = true;
170172
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
171173
// cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
172174
// name in line with the formula, not the reverse
@@ -582,6 +584,9 @@ protected function loadSpreadsheetFromFile2(string $filename, Xls $xls): Spreads
582584
$xls->phpSheet->setSelectedCells($selectedCells);
583585
}
584586
}
587+
if ($xls->createBlankSheetIfNoneRead && !$sheetCreated) {
588+
$xls->spreadsheet->createSheet();
589+
}
585590
if ($xls->activeSheetSet === false) {
586591
$xls->spreadsheet->setActiveSheetIndex(0);
587592
}

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
784784

785785
$charts = $chartDetails = [];
786786

787+
$sheetCreated = false;
787788
if ($xmlWorkbookNS->sheets) {
788789
foreach ($xmlWorkbookNS->sheets->sheet as $eleSheet) {
789790
$eleSheetAttr = self::getAttributes($eleSheet);
@@ -810,6 +811,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
810811

811812
// Load sheet
812813
$docSheet = $excel->createSheet();
814+
$sheetCreated = true;
813815
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet
814816
// references in formula cells... during the load, all formulae should be correct,
815817
// and we're simply bringing the worksheet name in line with the formula, not the
@@ -1897,6 +1899,9 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
18971899
}
18981900
}
18991901
}
1902+
if ($this->createBlankSheetIfNoneRead && !$sheetCreated) {
1903+
$excel->createSheet();
1904+
}
19001905

19011906
(new WorkbookView($excel))->viewSettings($xmlWorkbook, $mainNS, $mapSheetId, $this->readDataOnly);
19021907

src/PhpSpreadsheet/Reader/Xml.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet, boo
307307
$worksheetID = 0;
308308
$xml_ss = $xml->children(self::NAMESPACES_SS);
309309

310+
$sheetCreated = false;
310311
/** @var null|SimpleXMLElement $worksheetx */
311312
foreach ($xml_ss->Worksheet as $worksheetx) {
312313
$worksheet = $worksheetx ?? new SimpleXMLElement('<xml></xml>');
@@ -321,6 +322,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet, boo
321322

322323
// Create new Worksheet
323324
$spreadsheet->createSheet();
325+
$sheetCreated = true;
324326
$spreadsheet->setActiveSheetIndex($worksheetID);
325327
$worksheetName = '';
326328
if (isset($worksheet_ss['Name'])) {
@@ -668,6 +670,9 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet, boo
668670
}
669671
++$worksheetID;
670672
}
673+
if ($this->createBlankSheetIfNoneRead && !$sheetCreated) {
674+
$spreadsheet->createSheet();
675+
}
671676

672677
// Globally scoped defined names
673678
$activeSheetIndex = 0;

src/PhpSpreadsheet/Shared/StringHelper.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ class StringHelper
1919
"\x06",
2020
"\x07",
2121
"\x08",
22-
"\x09",
23-
"\x0a",
2422
"\x0b",
2523
"\x0c",
26-
"\x0d",
2724
"\x0e",
2825
"\x0f",
2926
"\x10",
@@ -53,11 +50,8 @@ class StringHelper
5350
'_x0006_',
5451
'_x0007_',
5552
'_x0008_',
56-
'_x0009_',
57-
'_x000A_',
5853
'_x000B_',
5954
'_x000C_',
60-
'_x000D_',
6155
'_x000E_',
6256
'_x000F_',
6357
'_x0010_',

src/PhpSpreadsheet/Worksheet/MemoryDrawing.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ public function __construct()
6464

6565
public function __destruct()
6666
{
67-
if ($this->imageResource) {
68-
@imagedestroy($this->imageResource);
69-
$this->imageResource = null;
70-
}
67+
$this->imageResource = null;
7168
$this->worksheet = null;
7269
}
7370

0 commit comments

Comments
 (0)