Skip to content

Commit b2d572c

Browse files
jenasnicjcopin
andauthored
Fix missing font index with some XLS files (#3734)
* Fix missing font index with some XLS files * Add test case * Improve Test --------- Co-authored-by: JC <[email protected]> Co-authored-by: jenasnic
1 parent 7872602 commit b2d572c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/PhpSpreadsheet/Reader/Xls.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,9 @@ private function readXf(): void
21162116
// check the OpenOffice documentation of the FONT record
21172117
$fontIndex = self::getUInt2d($recordData, 0) - 1;
21182118
}
2119-
$objStyle->setFont($this->objFonts[$fontIndex]);
2119+
if (isset($this->objFonts[$fontIndex])) {
2120+
$objStyle->setFont($this->objFonts[$fontIndex]);
2121+
}
21202122

21212123
// offset: 2; size: 2; Index to FORMAT record
21222124
$numberFormatIndex = self::getUInt2d($recordData, 2);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
6+
7+
use PhpOffice\PhpSpreadsheet\IOFactory;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class XlsBugPr3734Test extends TestCase
11+
{
12+
/**
13+
* Test XLS file including data with missing fonts?
14+
*/
15+
public function testXlsFileWithNoFontIndex(): void
16+
{
17+
$fileName = 'tests/data/Reader/XLS/bug-pr-3734.xls';
18+
$spreadsheet = IOFactory::load($fileName);
19+
$sheet = $spreadsheet->getActiveSheet();
20+
self::assertSame('Calibri', $sheet->getStyle('A1')->getFont()->getName());
21+
$spreadsheet->disconnectWorksheets();
22+
}
23+
}

tests/data/Reader/XLS/bug-pr-3734.xls

14.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)