Skip to content

[XLSX Reader] Chart title reference error #749

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

Closed
guillaume-ro-fr opened this issue Oct 29, 2018 · 1 comment
Closed

[XLSX Reader] Chart title reference error #749

guillaume-ro-fr opened this issue Oct 29, 2018 · 1 comment
Labels

Comments

@guillaume-ro-fr
Copy link
Contributor

This is:

- [x] a bug report

What is the expected behavior?

When the title of a chart is a cell reference, the title must be set.

What is the current behavior?

An error occurs because the title is not a rich text but a reference to a cell.

What are the steps to reproduce?

We can't reproduce this behavior on a chart from scratch, PhpSpreadsheet allow us to only put a string caption on a title.

Here the XML extract from an Excel chart :

<c:chart>
	<c:title>
		<c:tx>
			<c:strRef>
				<c:f>'Worksheet'!$B$41</c:f>
				<c:strCache>
					<c:ptCount val="1"/>
					<c:pt idx="0">
						<c:v>My super title in a cell !</c:v>
					</c:pt>
				</c:strCache>
			</c:strRef>
		</c:tx>
		<c:overlay val="0"/>
		<c:spPr>
			<a:noFill/>
			<a:ln>
				<a:noFill/>
			</a:ln>
			<a:effectLst/>
		</c:spPr>
                 ...
	</c:title>
</c:chart>

Here my draft for the fix (the value is not dynamic, the range is put directly as string in the title ...) :

private static function chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta)
    {
        $caption = [];
        $titleLayout = null;
        foreach ($titleDetails as $titleDetailKey => $chartDetail) {
            switch ($titleDetailKey) {
                case 'tx':
                    foreach ($chartDetail as $titleCaptionKey => $titleCaption) {
                        switch ($titleCaptionKey) {
                            case 'rich':
                                foreach ($titleCaption->children($namespacesChartMeta['a']) as $titleKey => $titleDetail) {
                                    switch ($titleKey) {
                                        case 'p':
                                            $titleDetailPart = $titleDetail->children($namespacesChartMeta['a']);
                                            $caption[] = self::parseRichText($titleDetailPart);
                                    }
                                }

                                break;
                            case 'strRef':
                                foreach ($titleCaption->children($namespacesChartMeta['c']) as $titleKey => $titleDetail) {
                                    switch ($titleKey) {
                                        case 'f':
                                            $caption[] = (string) $titleDetail;
                                    }
                                }
                        }
                    }

                    break;
                case 'layout':
                    $titleLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);

                    break;
            }
        }

        return new Title($caption, $titleLayout);
    }

I don't know if there is quick fix to transform the caption in dynamic value.

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.5.0
PHP 7.1

@stale
Copy link

stale bot commented Dec 28, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Dec 28, 2018
@stale stale bot closed this as completed Jan 5, 2019
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jul 29, 2022
This is a start in addressing issue PHPOffice#2965 (and earlier issue PHPOffice#749). Chart Titles are usually entered as strings or Rich Text strings, and PhpSpreadsheet supports that. They can also be entered as formulas (typically a pointer to a cell with the title text), and, not only did PhpSpreadsheet not support that, it threw an exception when reading a spreadsheet that did so.

This change does:
- eliminate the exception
- set a static chart title when it can determine it from the Xml

This change does not:
- fully support dynamic titles (e.g. if you change the contents of the source cell, or delete or insert cells or rows or columns)
- permit the user to set the title to a formula
- allow the use of formulas when writing a chart title to a spreadsheet
- provide styling for titles when it has read them as a formula
oleibman added a commit that referenced this issue Aug 7, 2022
This is a start in addressing issue #2965 (and earlier issue #749). Chart Titles are usually entered as strings or Rich Text strings, and PhpSpreadsheet supports that. They can also be entered as formulas (typically a pointer to a cell with the title text), and, not only did PhpSpreadsheet not support that, it threw an exception when reading a spreadsheet that did so.

This change does:
- eliminate the exception
- set a static chart title when it can determine it from the Xml

This change does not:
- fully support dynamic titles (e.g. if you change the contents of the source cell, or delete or insert cells or rows or columns)
- permit the user to set the title to a formula
- allow the use of formulas when writing a chart title to a spreadsheet
- provide styling for titles when it has read them as a formula
MarkBaker added a commit that referenced this issue Sep 25, 2022
### Added

- Implementation of the new `TEXTBEFORE()`, `TEXTAFTER()` and `TEXTSPLIT()` Excel Functions
- Implementation of the `ARRAYTOTEXT()` and `VALUETOTEXT()` Excel Functions
- Support for [mitoteam/jpgraph](https://packagist.org/packages/mitoteam/jpgraph) implementation of
  JpGraph library to render charts added.
- Charts: Add Gradients, Transparency, Hidden Axes, Rounded Corners, Trendlines, Date Axes.

### Changed

- Allow variant behaviour when merging cells [Issue #3065](#3065)
  - Merge methods now allow an additional `$behaviour` argument. Permitted values are:
    - Worksheet::MERGE_CELL_CONTENT_EMPTY - Empty the content of the hidden cells (the default behaviour)
    - Worksheet::MERGE_CELL_CONTENT_HIDE - Keep the content of the hidden cells
    - Worksheet::MERGE_CELL_CONTENT_MERGE - Move the content of the hidden cells into the first cell

### Deprecated

- Axis getLineProperty deprecated in favor of getLineColorProperty.
- Moved majorGridlines and minorGridlines from Chart to Axis. Setting either in Chart constructor or through Chart methods, or getting either using Chart methods is deprecated.
- Chart::EXCEL_COLOR_TYPE_* copied from Properties to ChartColor; use in Properties is deprecated.
- ChartColor::EXCEL_COLOR_TYPE_ARGB deprecated in favor of EXCEL_COLOR_TYPE_RGB ("A" component was never allowed).
- Misspelled Properties::LINE_STYLE_DASH_SQUERE_DOT deprecated in favor of LINE_STYLE_DASH_SQUARE_DOT.
- Clone not permitted for Spreadsheet. Spreadsheet->copy() can be used instead.

### Removed

- Nothing

### Fixed

- Fix update to defined names when inserting/deleting rows/columns [Issue #3076](#3076) [PR #3077](#3077)
- Fix DataValidation sqRef when inserting/deleting rows/columns [Issue #3056](#3056) [PR #3074](#3074)
- Named ranges not usable as anchors in OFFSET function [Issue #3013](#3013)
- Fully flatten an array [Issue #2955](#2955) [PR #2956](#2956)
- cellExists() and getCell() methods should support UTF-8 named cells [Issue #2987](#2987) [PR #2988](#2988)
- Spreadsheet copy fixed, clone disabled. [PR #2951](#2951)
- Fix PDF problems with text rotation and paper size. [Issue #1747](#1747) [Issue #1713](#1713) [PR #2960](#2960)
- Limited support for chart titles as formulas [Issue #2965](#2965) [Issue #749](#749) [PR #2971](#2971)
- Add Gradients, Transparency, and Hidden Axes to Chart [Issue #2257](#2257) [Issue #2229](#2929) [Issue #2935](#2935) [PR #2950](#2950)
- Chart Support for Rounded Corners and Trendlines [Issue #2968](#2968) [Issue #2815](#2815) [PR #2976](#2976)
- Add setName Method for Chart [Issue #2991](#2991) [PR #3001](#3001)
- Eliminate partial dependency on php-intl in StringHelper [Issue #2982](#2982) [PR #2994](#2994)
- Minor changes for Pdf [Issue #2999](#2999) [PR #3002](#3002) [PR #3006](#3006)
- Html/Pdf Do net set background color for cells using (default) nofill [PR #3016](#3016)
- Add support for Date Axis to Chart [Issue #2967](#2967) [PR #3018](#3018)
- Reconcile Differences Between Css and Excel for Cell Alignment [PR #3048](#3048)
- R1C1 Format Internationalization and Better Support for Relative Offsets [Issue #1704](#1704) [PR #3052](#3052)
- Minor Fix for Percentage Formatting [Issue #1929](#1929) [PR #3053](#3053)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant