Skip to content

Commit d593617

Browse files
authored
Fix font index problem (#2642)
* Fix font index problem * Update RichTextSizeTest.php Eliminate Phpstan failure. * Update RichTextSizeTest.php Eliminate now-unused import.
1 parent 9caa827 commit d593617

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/PhpSpreadsheet/Reader/Xls.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,8 +3759,13 @@ private function readLabelSst(): void
37593759
} else {
37603760
$textRun = $richText->createTextRun($text);
37613761
if (isset($fmtRuns[$i - 1])) {
3762-
$fontIndex = $fmtRuns[$i - 1]['fontIndex'];
3763-
3762+
if ($fmtRuns[$i - 1]['fontIndex'] < 4) {
3763+
$fontIndex = $fmtRuns[$i - 1]['fontIndex'];
3764+
} else {
3765+
// this has to do with that index 4 is omitted in all BIFF versions for some stra nge reason
3766+
// check the OpenOffice documentation of the FONT record
3767+
$fontIndex = $fmtRuns[$i - 1]['fontIndex'] - 1;
3768+
}
37643769
if (array_key_exists($fontIndex, $this->objFonts) === false) {
37653770
$fontIndex = count($this->objFonts) - 1;
37663771
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
4+
5+
use PhpOffice\PhpSpreadsheet\Reader\Xls;
6+
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
7+
8+
class RichTextSizeTest extends AbstractFunctional
9+
{
10+
public function testRichTextRunSize(): void
11+
{
12+
$filename = 'tests/data/Reader/XLS/RichTextFontSize.xls';
13+
$reader = new Xls();
14+
$spreadsheet = $reader->load($filename);
15+
$sheet = $spreadsheet->getSheetByName('橱柜门板');
16+
self::assertNotNull($sheet);
17+
$text = $sheet->getCell('L15')->getValue();
18+
$elements = $text->getRichTextElements();
19+
self::assertEquals(10, $elements[2]->getFont()->getSize());
20+
$spreadsheet->disconnectWorksheets();
21+
}
22+
}
52.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)