Skip to content

Inconsistent cell styles on RichText values. #1154

@AndrewDRX

Description

@AndrewDRX

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Consistency among TextElement styles of the same RichText value after applying a cell style. Desired behavior would be one of the following:

  1. Overwrite any applicable TextElement and Run styles.
  2. Overwrite any applicable TextElement styles, and ignore all Run styles.
  3. Ignore all TextElement and Run styles.

What is the current behavior?

Inconsistency among TextElement styles of the same RichText value after applying a cell style. Current behavior is that setting a cell style only overwrites any applicable TextElement styles found before a Run style; any TextElement styles found after a Run style are ignored.

What are the steps to reproduce?

<?php
require_once 'vendor/autoload.php';

use \PhpOffice\PhpSpreadsheet\Spreadsheet;
use \PhpOffice\PhpSpreadsheet\RichText\RichText;
use \PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$workbook = new Spreadsheet();

$rtf = new RichText();

/* This segment will receive applied cell styles. */
$rtf->createText('~Cell Style~');

/* This segment ignore applied cell styles. */
$rtf->createTextRun('~RTF Style~')->getFont()->setItalic(true);

/* This segment will also ignore applied cell styles. */
$rtf->createText('~No Style~');

$sheet = $workbook->getSheet(0);
$sheet->getCell('A1')->setValue($rtf);
$sheet->getStyle('A1')->getFont()->setBold(true);

(new Xlsx($workbook))->save('output.xlsx');

$workbook->disconnectWorksheets();
unset($workbook);

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet [1.9]
PHP [7.1.27]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions