Skip to content

Keep cell number formats when plotting chart data from a sheet range - #1189

Open
kamilkrzywanski wants to merge 4 commits into
apache:trunkfrom
kamilkrzywanski:fix-1007-chart-cell-number-formats
Open

Keep cell number formats when plotting chart data from a sheet range#1189
kamilkrzywanski wants to merge 4 commits into
apache:trunkfrom
kamilkrzywanski:fix-1007-chart-cell-number-formats

Conversation

@kamilkrzywanski

Copy link
Copy Markdown

When chart data is built with fromNumericCellRange and then plot() is called, the series format code in the chart numCache was left empty (and any existing format was cleared). PowerPoint then shows unformatted data labels if they are linked to source, until the embedded workbook is opened in Excel and the cache is refreshed.

This change reads number formats from the cells, uses the first non-blank numeric cell as the series format, and writes a per-point format when it differs. setFormatCode(...) still overrides the series format. Includes a regression test.

Fixes #1007

fromNumericCellRange left formatCode null, so plot() cleared the chart
numCache format and data labels linked to source showed unformatted
values. Read formats from the cells and write them into the cache.

Fixes apache#1007
Comment thread poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java Outdated
Signed-off-by: Kamil Krzywanski <kamilkrzywanski01@gmail.com>
@pjfanning

Copy link
Copy Markdown
Member

@kamilkrzywanski I still don't understand what you intend null to mean. The updated javadoc doesn't give me any hints. Can you provide a comment describing what you want and I can update the Javadoc?

Comment thread poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java Outdated
Comment thread poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java Outdated
@kamilkrzywanski

Copy link
Copy Markdown
Author

@pjfanning glad that clicked. Yes, NumericalCellRangeDataSource is the real override; default null keeps other sources series-only.

On the Javadoc: null means use the series format from getFormatCode(), not always Excel's global default. Happy for you to reword it, or I can push a small Javadoc tweak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: the number format is not updated after updating the XSLFChart in the presentation

2 participants