-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RichText can not get the correct value, when one part is plain text and the other part is rich text. #442
Comments
I can confirm that the problem exists in 1.2.0 and was gone after downgrading to 1.1.0 |
Have tested the proposed solution, can confirm it works fine. |
Code in below can reproduce the bug. (Prepare an empty xlsx file) $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('empty.xlsx');
$worksheet = $spreadsheet->getActiveSheet();
$richText = new \PhpOffice\PhpSpreadsheet\RichText\RichText();
$richText->createText('plain text');
$payable = $richText->createTextRun('rich text');
$payable->getFont()->setBold(true);
$payable->getFont()->setColor( new \PhpOffice\PhpSpreadsheet\Style\Color( \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN ) );
$worksheet->getCell('A1')->setValue($richText);
$output = "richtext.xlsx";
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
$writer->save($output);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($output);
$worksheet = $spreadsheet->getActiveSheet();
$cell = $worksheet->getCell('A1');
/** @var \PhpOffice\PhpSpreadsheet\RichText\RichText $value */
$value = $cell->getValue();
echo $value->getPlainText();
// output: 'rich text' |
Hi. I'm facing the same problem. I'm having, in an .xlsx file, with some rows that contains plain text, part of it containing styles like: underline, bold or italic, and some of them without.
Here's my case.
Using this
I expect to get, for example, that bold And one more issue, the Any tip to fix the issues! Thanks! LE: And downgrading to v1.1.0 as BlueM suggested, didn't help. |
Yup, same issue here. v1.2.0 |
current develop branch (@ 5f03659) still has the issue |
This was introduced in 0084776 Fixes PHPOffice#442 Closes PHPOffice#453
This is:
What is the expected behavior?
When I use RichText()->getPlainText(), I should get complete text, contain plain text and rich text.
What is the current behavior?
In xlsx, Like cell value: "plain text, rich text", RichText()->getPlainText() only return the rich text part("rich text"). the first part is missing.
What are the steps to reproduce?
In source code https://github.com/PHPOffice/PhpSpreadsheet/blob/develop/src/PhpSpreadsheet/Reader/Xlsx.php, line 2070
missing the else part.
It should be
In Xlsx, a cell can contain part to plain text, and the other part of rich text.
In above, $run element can only have "t" attribute.
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 1.2.0, PHP 7.1.6.
The text was updated successfully, but these errors were encountered: