Skip to content

Commit 9930e70

Browse files
author
Yegor Kozlov
committed
added Workbook.getForceFormulaRecalculation as requested in Bug 51422
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1141585 13f79535-47bb-0310-9956-ffa450edef68
1 parent 793d119 commit 9930e70

File tree

7 files changed

+47
-1
lines changed

7 files changed

+47
-1
lines changed

src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,4 +1792,16 @@ public void setForceFormulaRecalculation(boolean value){
17921792
recalc.setEngineId(0);
17931793
}
17941794

1795+
/**
1796+
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
1797+
*
1798+
* @since 3.8
1799+
*/
1800+
public boolean getForceFormulaRecalculation(){
1801+
InternalWorkbook iwb = getWorkbook();
1802+
RecalcIdRecord recalc = (RecalcIdRecord)iwb.findFirstRecordBySid(RecalcIdRecord.sid);
1803+
return recalc != null && recalc.getEngineId() != 0;
1804+
}
1805+
1806+
17951807
}

src/java/org/apache/poi/ss/usermodel/Sheet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public interface Sheet extends Iterable<Row> {
319319
void setForceFormulaRecalculation(boolean value);
320320

321321
/**
322-
* Whether Excel will be asked to recalculate all formulas when the
322+
* Whether Excel will be asked to recalculate all formulas in this sheet when the
323323
* workbook is opened.
324324
*/
325325
boolean getForceFormulaRecalculation();

src/java/org/apache/poi/ss/usermodel/Workbook.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,11 @@ public interface Workbook {
564564
*/
565565
public void setForceFormulaRecalculation(boolean value);
566566

567+
/**
568+
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
569+
*
570+
* @since 3.8
571+
*/
572+
boolean getForceFormulaRecalculation();
573+
567574
}

src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,5 +835,12 @@ public void setForceFormulaRecalculation(boolean value){
835835
_wb.setForceFormulaRecalculation(value);
836836
}
837837

838+
/**
839+
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
840+
*/
841+
public boolean getForceFormulaRecalculation(){
842+
return _wb.getForceFormulaRecalculation();
843+
}
844+
838845
//end of interface implementation
839846
}

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,4 +1596,16 @@ public void setForceFormulaRecalculation(boolean value){
15961596
// in the workbook the next time the file is opened.
15971597
calcPr.setCalcId(0);
15981598
}
1599+
1600+
/**
1601+
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
1602+
*
1603+
* @since 3.8
1604+
*/
1605+
public boolean getForceFormulaRecalculation(){
1606+
CTWorkbook ctWorkbook = getCTWorkbook();
1607+
CTCalcPr calcPr = ctWorkbook.getCalcPr();
1608+
return calcPr != null && calcPr.getCalcId() != 0;
1609+
}
1610+
15991611
}

src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ public void testBug49702() throws Exception {
410410

411411
public void testRecalcId() {
412412
XSSFWorkbook wb = new XSSFWorkbook();
413+
assertFalse(wb.getForceFormulaRecalculation());
413414
CTWorkbook ctWorkbook = wb.getCTWorkbook();
414415
assertFalse(ctWorkbook.isSetCalcPr());
415416

@@ -420,8 +421,11 @@ public void testRecalcId() {
420421
assertEquals(0, (int) calcPr.getCalcId());
421422

422423
calcPr.setCalcId(100);
424+
assertTrue(wb.getForceFormulaRecalculation());
425+
423426
wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
424427
assertEquals(0, (int) calcPr.getCalcId());
428+
assertFalse(wb.getForceFormulaRecalculation());
425429
}
426430

427431
}

src/testcases/org/apache/poi/hssf/model/TestWorkbook.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
119119

120120
public void testRecalcId(){
121121
HSSFWorkbook wb = new HSSFWorkbook();
122+
assertFalse(wb.getForceFormulaRecalculation());
123+
122124
InternalWorkbook iwb = TestHSSFWorkbook.getInternalWorkbook(wb);
123125
int countryPos = iwb.findFirstRecordLocBySid(CountryRecord.sid);
124126
assertTrue(countryPos != -1);
@@ -133,8 +135,10 @@ public void testRecalcId(){
133135

134136
record.setEngineId(100);
135137
assertEquals(100, record.getEngineId());
138+
assertTrue(wb.getForceFormulaRecalculation());
136139

137140
wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
138141
assertEquals(0, record.getEngineId());
142+
assertFalse(wb.getForceFormulaRecalculation());
139143
}
140144
}

0 commit comments

Comments
 (0)