Bugzilla 53950 - fixed setForceFormulaRecalculation to reset workbook-level manual flag<

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1394059 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2012-10-04 13:26:44 +00:00
parent 57bbac29fe
commit 141294063d
5 changed files with 29 additions and 7 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.9-beta1" date="2012-??-??">
<action dev="poi-developers" type="fix">53950 - fixed setForceFormulaRecalculation to reset workbook-level "manual" flag</action>
<action dev="poi-developers" type="fix">52211 - avoid unnessary re-coverting content types to US-ASCII, it can cause exceptions on ibm mainframes</action>
<action dev="poi-developers" type="fix">53568 - Set shapes anchors in XSSF when reading from existing drawings</action>
<action dev="poi-developers" type="add">HSSFOptimiser will now also tidy away un-used cell styles, in addition to duplicate styles</action>

View File

@ -1502,7 +1502,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* @see org.apache.poi.ss.usermodel.Workbook#setForceFormulaRecalculation(boolean)
*/
public void setForceFormulaRecalculation(boolean value) {
if(worksheet.isSetSheetCalcPr()) {
CTCalcPr calcPr = getWorkbook().getCTWorkbook().getCalcPr();
if(worksheet.isSetSheetCalcPr()) {
// Change the current setting
CTSheetCalcPr calc = worksheet.getSheetCalcPr();
calc.setFullCalcOnLoad(value);
@ -1512,9 +1514,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
CTSheetCalcPr calc = worksheet.addNewSheetCalcPr();
calc.setFullCalcOnLoad(value);
}
else {
// Not set, requested not, nothing to do
}
if(value && calcPr != null && calcPr.getCalcMode() == STCalcMode.MANUAL) {
calcPr.setCalcMode(STCalcMode.AUTO);
}
}
/**

View File

@ -1672,6 +1672,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
// when set to 0, will tell Excel that it needs to recalculate all formulas
// in the workbook the next time the file is opened.
calcPr.setCalcId(0);
if(value && calcPr.getCalcMode() == STCalcMode.MANUAL) {
calcPr.setCalcMode(STCalcMode.AUTO);
}
}
/**

View File

@ -1074,11 +1074,18 @@ public final class TestXSSFSheet extends BaseTestSheet {
// Set
sheet.setForceFormulaRecalculation(true);
assertEquals(true, sheet.getForceFormulaRecalculation());
// Check
// calcMode="manual" is unset when forceFormulaRecalculation=true
CTCalcPr calcPr = workbook.getCTWorkbook().addNewCalcPr();
calcPr.setCalcMode(STCalcMode.MANUAL);
sheet.setForceFormulaRecalculation(true);
assertEquals(STCalcMode.AUTO, calcPr.getCalcMode());
// Check
sheet.setForceFormulaRecalculation(false);
assertEquals(false, sheet.getForceFormulaRecalculation());
// Save, re-load, and re-check
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
sheet = workbook.getSheet("Sheet 1");

View File

@ -35,6 +35,7 @@ import org.apache.poi.xssf.model.StylesTable;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode;
public final class TestXSSFWorkbook extends BaseTestWorkbook {
@ -426,6 +427,12 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
assertEquals(0, (int) calcPr.getCalcId());
assertFalse(wb.getForceFormulaRecalculation());
// calcMode="manual" is unset when forceFormulaRecalculation=true
calcPr.setCalcMode(STCalcMode.MANUAL);
wb.setForceFormulaRecalculation(true);
assertEquals(STCalcMode.AUTO, calcPr.getCalcMode());
}
public void testChangeSheetNameWithSharedFormulas() {