Browse Source

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
tags/REL_3_7_BETA3
Nick Burch 13 years ago
parent
commit
8d0eb2afe9

+ 1
- 0
src/documentation/content/xdocs/status.xml View File



<changes> <changes>
<release version="3.7-beta3" date="2010-??-??"> <release version="3.7-beta3" date="2010-??-??">
<action dev="poi-developers" type="fix">49966 - Correctly remove calcChain entries for XSSF cells that stop holding formulas</action>
<action dev="poi-developers" type="add">47582 - XSSFCellStyle support for creating a style in one workbook based on a style from a different one</action> <action dev="poi-developers" type="add">47582 - XSSFCellStyle support for creating a style in one workbook based on a style from a different one</action>
<action dev="poi-developers" type="fix">49931 - Avoid concurrency problems when re-ordering multiple HSSF header records for a PageSettingsBlock</action> <action dev="poi-developers" type="fix">49931 - Avoid concurrency problems when re-ordering multiple HSSF header records for a PageSettingsBlock</action>
<action dev="poi-developers" type="fix">49765 - Fix XWPFDocument.addPicture so that it correctly sets up relationships</action> <action dev="poi-developers" type="fix">49765 - Fix XWPFDocument.addPicture so that it correctly sets up relationships</action>

+ 6
- 2
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java View File

* @see #CELL_TYPE_ERROR * @see #CELL_TYPE_ERROR
*/ */
public void setCellType(int cellType) { public void setCellType(int cellType) {
int prevType = getCellType();
if(isPartOfArrayFormulaGroup()){ if(isPartOfArrayFormulaGroup()){
notifyArrayFormulaChanging(); notifyArrayFormulaChanging();
} }

int prevType = getCellType();
if(prevType == CELL_TYPE_FORMULA && cellType != CELL_TYPE_FORMULA) {
getSheet().getWorkbook().onDeleteFormula(this);
}
switch (cellType) { switch (cellType) {
case CELL_TYPE_BLANK: case CELL_TYPE_BLANK:
setBlank(); setBlank();

+ 4
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java View File

} }


XSSFCell xcell = (XSSFCell)cell; XSSFCell xcell = (XSSFCell)cell;
if(xcell.isPartOfArrayFormulaGroup()){
if(xcell.isPartOfArrayFormulaGroup()) {
xcell.notifyArrayFormulaChanging(); xcell.notifyArrayFormulaChanging();
} }
if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
_sheet.getWorkbook().onDeleteFormula(xcell);
}
_cells.remove(cell.getColumnIndex()); _cells.remove(cell.getColumnIndex());
} }



+ 1
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java View File

//delete the CTSheet reference from workbook.xml //delete the CTSheet reference from workbook.xml
workbook.getSheets().removeSheet(index); workbook.getSheets().removeSheet(index);


//calculation chain is auxilary, remove it as it may contain orfan references to deleted cells
//calculation chain is auxiliary, remove it as it may contain orphan references to deleted cells
if(calcChain != null) { if(calcChain != null) {
removeRelation(calcChain); removeRelation(calcChain);
calcChain = null; calcChain = null;

+ 38
- 0
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java View File

import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;


} }
} }


/**
* Various ways of removing a cell formula should all zap
* the calcChain entry.
*/
public void test49966() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("shared_formulas.xlsx");
XSSFSheet sheet = wb.getSheetAt(0);
// CalcChain has lots of entries
CalculationChain cc = wb.getCalculationChain();
assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
assertEquals("A3", cc.getCTCalcChain().getCArray(1).getR());
assertEquals("A4", cc.getCTCalcChain().getCArray(2).getR());
assertEquals("A5", cc.getCTCalcChain().getCArray(3).getR());
assertEquals("A6", cc.getCTCalcChain().getCArray(4).getR());
assertEquals("A7", cc.getCTCalcChain().getCArray(5).getR());
// Try various ways of changing the formulas
// If it stays a formula, chain entry should remain
// Otherwise should go
sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
sheet.getRow(2).getCell(0).setCellFormula(null); // go
sheet.getRow(3).getCell(0).setCellType(Cell.CELL_TYPE_FORMULA); // stay
sheet.getRow(4).getCell(0).setCellType(Cell.CELL_TYPE_STRING); // go
sheet.getRow(5).removeCell(
sheet.getRow(5).getCell(0) // go
);
// Save and check
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
cc = wb.getCalculationChain();
assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
assertEquals("A4", cc.getCTCalcChain().getCArray(1).getR());
assertEquals("A7", cc.getCTCalcChain().getCArray(2).getR());
}
} }

Loading…
Cancel
Save