-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect font color read from xlsx
Place the read font color after setting the styles
- Loading branch information
Showing
3 changed files
with
59 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
use PhpOffice\PhpSpreadsheet\RichText\RichText; | ||
|
||
class Issue3464Test extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private static $testbook = 'tests/data/Reader/XLSX/issue.3464.xlsx'; | ||
|
||
public function testReadFontColor(): void | ||
{ | ||
$inputFileType = IOFactory::identify(self::$testbook); | ||
$objReader = IOFactory::createReader($inputFileType); | ||
$objReader->setReadEmptyCells(false); | ||
|
||
$sheet = $objReader->load(self::$testbook)->getActiveSheet(); | ||
$rickText = $sheet->getCell([1, 1])->getValue(); | ||
self::assertInstanceOf(RichText::class, $rickText); | ||
|
||
$elements = $rickText->getRichTextElements(); | ||
self::assertCount(2, $elements); | ||
|
||
self::assertEquals("产品介绍\n", $elements[0]->getText()); | ||
$font = $elements[0]->getFont(); | ||
self::assertNotNull($font); | ||
self::assertEquals('7f7f7f', $font->getColor()->getRGB()); | ||
|
||
self::assertEquals('(这是一行示例数据,在导入时需要删除该行)', $elements[1]->getText()); | ||
$font = $elements[1]->getFont(); | ||
self::assertNotNull($font); | ||
self::assertEquals('ff2600', $font->getColor()->getRGB()); | ||
} | ||
} |
Binary file not shown.