You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "emmanueldufour (via GitHub)" <gi...@apache.org> on 2025/12/17 07:42:47 UTC
[PR] Update XWPFChart.java [poi]
emmanueldufour opened a new pull request, #974:
URL: https://github.com/apache/poi/pull/974
Word keeps cached values that need be refreshed after the embedded workbook has been updated. This is just the first step refreshing categories and series labels (tested for bar charts).
see for ex:
https://stackoverflow.com/questions/74703330/updated-excel-chart-in-word-document-not-getting-reflected-apache-poi
https://stackoverflow.com/questions/54681481/apache-poi-when-editing-chart-data-in-a-word-file-it-returns-to-the-data-defi
TODO ultimately a function should be provided to refresh the entire chart cache
TODO getWorkbookCells and getWorkbookCellVallue should be moved to XSSFWorkbook
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #974:
URL: https://github.com/apache/poi/pull/974#discussion_r2630416941
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java:
##########
@@ -58,7 +70,7 @@ public class XWPFChart extends XDDFChart {
* constructor to
* Create a new chart in document
*
- * @since 4.0.0
+ * @since POI 4.0.0
Review Comment:
I wasn't offering to do it. I was asking why I'm expected to do it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #974:
URL: https://github.com/apache/poi/pull/974#discussion_r2630365112
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java:
##########
@@ -58,7 +70,7 @@ public class XWPFChart extends XDDFChart {
* constructor to
* Create a new chart in document
*
- * @since 4.0.0
+ * @since POI 4.0.0
Review Comment:
what can I revert in your PR?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #974:
URL: https://github.com/apache/poi/pull/974#discussion_r2630358005
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java:
##########
@@ -258,12 +270,76 @@ public long getChartRightMargin(long margin) {
* @param right margin from right
* @param bottom margin from bottom
* @param left margin from left
- * @since 4.0.0
+ * @since POI 4.0.0
*/
public void setChartMargin(long top, long right, long bottom, long left) {
this.setChartBottomMargin(bottom);
this.setChartRightMargin(right);
this.setChartLeftMargin(left);
this.setChartRightMargin(right);
}
+ /**
+ * Word keeps cached values that need be refreshed after the embedded workbook
+ * has been updated. This is just the first step refreshing categories and
+ * series labels (tested for bar charts). TODO ultimately a function should be
+ * provided to refresh the entire cache
+ */
+ public void refreshCachedLabels() {
+ Workbook wb;
+ try {
+ wb = getWorkbook();
+ } catch (InvalidFormatException | IOException e) {
+ return;
+ }
+ for (XDDFChartData chartData : getChartSeries()) {
+ for (int chartIndex = 0; chartIndex < chartData.getSeriesCount(); chartIndex++) {
+ XDDFChartData.Series series = chartData.getSeries(chartIndex);
+ String freshSeriesTitle=getWorkbookCellValue( series.getTitleReference(),wb);
+ series.setTitleCached(freshSeriesTitle);
+ XDDFDataSource<?> catData = series.getCategoryData();
+ if (catData == null)
+ continue;
+ String referenceFormula = catData.getFormula();
+ if (referenceFormula != null) {
+ List<Cell> cells = getWorkbookCells(referenceFormula, wb);
+ String[] freshCategories = new String[cells.size()];
+ int categIndex = 0;
+ for (Cell cell : cells) {
+ freshCategories[categIndex++] = cell.toString();
+ }
+ // create categories from a range formula and the values below, it will create then as "cached" values like word expects
+ XDDFDataSource<String> freshCategoryDataSrouce = XDDFDataSourcesFactory.fromArray(freshCategories,referenceFormula);
+ series.replaceData(freshCategoryDataSrouce, (XDDFNumericalDataSource<?>) series.getValuesData());
+ }
+ }
+ //this mystery "plot" will somehow update the underlying document XML
+ plot(chartData);
+ }
+ }
+ /**
+ *
+ * @param cell must include the sheet reference
+ * @param wb
+ * @return toString() value of the cell
+ */
+ private static String getWorkbookCellValue(CellReference cell, Workbook wb) {
+
+ return wb.getSheet( cell.getSheetName()).getRow(cell.getRow()).getCell(cell.getCol()).toString();
+
+ }
+ /**
Review Comment:
whitespace between methods - no need for all the whitespace inside the method - please try to make the code follow the existing style in classes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "emmanueldufour (via GitHub)" <gi...@apache.org>.
emmanueldufour commented on PR #974:
URL: https://github.com/apache/poi/pull/974#issuecomment-3669400271
> It is against ASF licensing policies to use code from stackoverflow.com due to the restrictive licensing that they apply to code on the site. You need to get the people who wrote the code to place the code in the public domain or license it with a more permissive license. https://www.apache.org/legal/resolved.html#stackoverflow
I did not use code from stackoverflow. I merely quoted related issues this is supposed to help with.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "emmanueldufour (via GitHub)" <gi...@apache.org>.
emmanueldufour commented on PR #974:
URL: https://github.com/apache/poi/pull/974#issuecomment-3669381550
> Can you start with using descriptive names for both your PRs?
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #974:
URL: https://github.com/apache/poi/pull/974#issuecomment-3669381906
It is against ASF licensing policies to use code from stackoverflow.com due to the restrictive licensing that they apply to code on the site. You need to get the people who wrote the code to place the code in the public domain or license it with a more permissive license.
https://www.apache.org/legal/resolved.html#stackoverflow
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #974:
URL: https://github.com/apache/poi/pull/974#discussion_r2630353620
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java:
##########
@@ -58,7 +70,7 @@ public class XWPFChart extends XDDFChart {
* constructor to
* Create a new chart in document
*
- * @since 4.0.0
+ * @since POI 4.0.0
Review Comment:
don't change these values
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "emmanueldufour (via GitHub)" <gi...@apache.org>.
emmanueldufour commented on code in PR #974:
URL: https://github.com/apache/poi/pull/974#discussion_r2630403838
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java:
##########
@@ -58,7 +70,7 @@ public class XWPFChart extends XDDFChart {
* constructor to
* Create a new chart in document
*
- * @since 4.0.0
+ * @since POI 4.0.0
Review Comment:
since 4.0.0 vs since POI 4.0.0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "emmanueldufour (via GitHub)" <gi...@apache.org>.
emmanueldufour commented on code in PR #974:
URL: https://github.com/apache/poi/pull/974#discussion_r2630356789
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java:
##########
@@ -58,7 +70,7 @@ public class XWPFChart extends XDDFChart {
* constructor to
* Create a new chart in document
*
- * @since 4.0.0
+ * @since POI 4.0.0
Review Comment:
yes sorry I didnt intend to but Im struggling with GIT, if you could revert it that would help
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] refresh XWPFChart.java cache from embedded values [poi]
Posted by "emmanueldufour (via GitHub)" <gi...@apache.org>.
emmanueldufour commented on code in PR #974:
URL: https://github.com/apache/poi/pull/974#discussion_r2630403838
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java:
##########
@@ -58,7 +70,7 @@ public class XWPFChart extends XDDFChart {
* constructor to
* Create a new chart in document
*
- * @since 4.0.0
+ * @since POI 4.0.0
Review Comment:
@since 4.0.0 vs @since POI 4.0.0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Update XWPFChart.java [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #974:
URL: https://github.com/apache/poi/pull/974#issuecomment-3669366966
Can you start with using descriptive names for both your PRs?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org