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 <jcopin@nodevo.com>
Co-authored-by: jenasnic
This commit is contained in:
jenasnic
2023-09-18 10:33:33 +02:00
committed by GitHub
parent 7872602136
commit b2d572c8bb
3 changed files with 26 additions and 1 deletions
+3 -1
View File
@@ -2116,7 +2116,9 @@ class Xls extends BaseReader
// check the OpenOffice documentation of the FONT record
$fontIndex = self::getUInt2d($recordData, 0) - 1;
}
$objStyle->setFont($this->objFonts[$fontIndex]);
if (isset($this->objFonts[$fontIndex])) {
$objStyle->setFont($this->objFonts[$fontIndex]);
}
// offset: 2; size: 2; Index to FORMAT record
$numberFormatIndex = self::getUInt2d($recordData, 2);
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;
class XlsBugPr3734Test extends TestCase
{
/**
* Test XLS file including data with missing fonts?
*/
public function testXlsFileWithNoFontIndex(): void
{
$fileName = 'tests/data/Reader/XLS/bug-pr-3734.xls';
$spreadsheet = IOFactory::load($fileName);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('Calibri', $sheet->getStyle('A1')->getFont()->getName());
$spreadsheet->disconnectWorksheets();
}
}
Binary file not shown.