mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-01 04:59:14 +00:00
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:
@@ -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.
Reference in New Issue
Block a user