From 39a185e9a7950071f3d1aed804659f0c54d66f9a Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 21 Sep 2010 11:16:12 +0000 Subject: [PATCH] Fix bug #49966 - Correctly remove calcChain entries for XSSF cells that stop holding formulas git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@999314 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/xssf/usermodel/XSSFCell.java | 8 +++- .../apache/poi/xssf/usermodel/XSSFRow.java | 5 ++- .../poi/xssf/usermodel/XSSFWorkbook.java | 2 +- .../poi/xssf/usermodel/TestXSSFBugs.java | 38 +++++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 736f3549b..81a4a3bea 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 49966 - Correctly remove calcChain entries for XSSF cells that stop holding formulas 47582 - XSSFCellStyle support for creating a style in one workbook based on a style from a different one 49931 - Avoid concurrency problems when re-ordering multiple HSSF header records for a PageSettingsBlock 49765 - Fix XWPFDocument.addPicture so that it correctly sets up relationships diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 93efe4b37..e0998bc59 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -721,11 +721,15 @@ public final class XSSFCell implements Cell { * @see #CELL_TYPE_ERROR */ public void setCellType(int cellType) { + int prevType = getCellType(); + if(isPartOfArrayFormulaGroup()){ notifyArrayFormulaChanging(); } - - int prevType = getCellType(); + if(prevType == CELL_TYPE_FORMULA && cellType != CELL_TYPE_FORMULA) { + getSheet().getWorkbook().onDeleteFormula(this); + } + switch (cellType) { case CELL_TYPE_BLANK: setBlank(); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java index 53747f5e3..f61717f47 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -365,9 +365,12 @@ public class XSSFRow implements Row, Comparable { } XSSFCell xcell = (XSSFCell)cell; - if(xcell.isPartOfArrayFormulaGroup()){ + if(xcell.isPartOfArrayFormulaGroup()) { xcell.notifyArrayFormulaChanging(); } + if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) { + _sheet.getWorkbook().onDeleteFormula(xcell); + } _cells.remove(cell.getColumnIndex()); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 8ae7f9a85..00d2ffee7 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -833,7 +833,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable