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
This commit is contained in:
Yegor Kozlov 2011-06-30 15:54:04 +00:00
parent 586645ade8
commit a3cad58fa8
7 changed files with 47 additions and 1 deletions

View File

@ -1792,4 +1792,16 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
recalc.setEngineId(0);
}
/**
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
*
* @since 3.8
*/
public boolean getForceFormulaRecalculation(){
InternalWorkbook iwb = getWorkbook();
RecalcIdRecord recalc = (RecalcIdRecord)iwb.findFirstRecordBySid(RecalcIdRecord.sid);
return recalc != null && recalc.getEngineId() != 0;
}
}

View File

@ -319,7 +319,7 @@ public interface Sheet extends Iterable<Row> {
void setForceFormulaRecalculation(boolean value);
/**
* Whether Excel will be asked to recalculate all formulas when the
* Whether Excel will be asked to recalculate all formulas in this sheet when the
* workbook is opened.
*/
boolean getForceFormulaRecalculation();

View File

@ -564,4 +564,11 @@ public interface Workbook {
*/
public void setForceFormulaRecalculation(boolean value);
/**
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
*
* @since 3.8
*/
boolean getForceFormulaRecalculation();
}

View File

@ -835,5 +835,12 @@ public class SXSSFWorkbook implements Workbook
_wb.setForceFormulaRecalculation(value);
}
/**
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
*/
public boolean getForceFormulaRecalculation(){
return _wb.getForceFormulaRecalculation();
}
//end of interface implementation
}

View File

@ -1596,4 +1596,16 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
// in the workbook the next time the file is opened.
calcPr.setCalcId(0);
}
/**
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
*
* @since 3.8
*/
public boolean getForceFormulaRecalculation(){
CTWorkbook ctWorkbook = getCTWorkbook();
CTCalcPr calcPr = ctWorkbook.getCalcPr();
return calcPr != null && calcPr.getCalcId() != 0;
}
}

View File

@ -410,6 +410,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
public void testRecalcId() {
XSSFWorkbook wb = new XSSFWorkbook();
assertFalse(wb.getForceFormulaRecalculation());
CTWorkbook ctWorkbook = wb.getCTWorkbook();
assertFalse(ctWorkbook.isSetCalcPr());
@ -420,8 +421,11 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertEquals(0, (int) calcPr.getCalcId());
calcPr.setCalcId(100);
assertTrue(wb.getForceFormulaRecalculation());
wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
assertEquals(0, (int) calcPr.getCalcId());
assertFalse(wb.getForceFormulaRecalculation());
}
}

View File

@ -119,6 +119,8 @@ public final class TestWorkbook extends TestCase {
public void testRecalcId(){
HSSFWorkbook wb = new HSSFWorkbook();
assertFalse(wb.getForceFormulaRecalculation());
InternalWorkbook iwb = TestHSSFWorkbook.getInternalWorkbook(wb);
int countryPos = iwb.findFirstRecordLocBySid(CountryRecord.sid);
assertTrue(countryPos != -1);
@ -133,8 +135,10 @@ public final class TestWorkbook extends TestCase {
record.setEngineId(100);
assertEquals(100, record.getEngineId());
assertTrue(wb.getForceFormulaRecalculation());
wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
assertEquals(0, record.getEngineId());
assertFalse(wb.getForceFormulaRecalculation());
}
}