use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr in project poi by apache.
the class XSSFWorkbook method getForceFormulaRecalculation.
/**
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
*
* @since 3.8
*/
@Override
public boolean getForceFormulaRecalculation() {
CTWorkbook ctWorkbook = getCTWorkbook();
CTCalcPr calcPr = ctWorkbook.getCalcPr();
return calcPr != null && calcPr.getCalcId() != 0;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr in project poi by apache.
the class TestXSSFSheet method setForceFormulaRecalculation.
/**
* Test to trigger OOXML-LITE generating to include org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr
*/
@Test
public void setForceFormulaRecalculation() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("Sheet 1");
assertFalse(sheet.getForceFormulaRecalculation());
// Set
sheet.setForceFormulaRecalculation(true);
assertTrue(sheet.getForceFormulaRecalculation());
// calcMode="manual" is unset when forceFormulaRecalculation=true
CTCalcPr calcPr = wb1.getCTWorkbook().addNewCalcPr();
calcPr.setCalcMode(STCalcMode.MANUAL);
sheet.setForceFormulaRecalculation(true);
assertEquals(STCalcMode.AUTO, calcPr.getCalcMode());
// Check
sheet.setForceFormulaRecalculation(false);
assertFalse(sheet.getForceFormulaRecalculation());
// Save, re-load, and re-check
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sheet = wb2.getSheet("Sheet 1");
assertFalse(sheet.getForceFormulaRecalculation());
wb2.close();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr in project poi by apache.
the class XSSFWorkbook method setForceFormulaRecalculation.
/**
* Whether the application shall perform a full recalculation when the workbook is opened.
* <p>
* Typically you want to force formula recalculation when you modify cell formulas or values
* of a workbook previously created by Excel. When set to true, this flag will tell Excel
* that it needs to recalculate all formulas in the workbook the next time the file is opened.
* </p>
* <p>
* Note, that recalculation updates cached formula results and, thus, modifies the workbook.
* Depending on the version, Excel may prompt you with "Do you want to save the changes in <em>filename</em>?"
* on close.
* </p>
*
* @param value true if the application will perform a full recalculation of
* workbook values when the workbook is opened
* @since 3.8
*/
@Override
public void setForceFormulaRecalculation(boolean value) {
CTWorkbook ctWorkbook = getCTWorkbook();
CTCalcPr calcPr = ctWorkbook.isSetCalcPr() ? ctWorkbook.getCalcPr() : ctWorkbook.addNewCalcPr();
// 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);
}
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr in project poi by apache.
the class TestXSSFWorkbook method recalcId.
@Test
public void recalcId() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
try {
assertFalse(wb.getForceFormulaRecalculation());
CTWorkbook ctWorkbook = wb.getCTWorkbook();
assertFalse(ctWorkbook.isSetCalcPr());
// resets the EngineId flag to zero
wb.setForceFormulaRecalculation(true);
CTCalcPr calcPr = ctWorkbook.getCalcPr();
assertNotNull(calcPr);
assertEquals(0, (int) calcPr.getCalcId());
calcPr.setCalcId(100);
assertTrue(wb.getForceFormulaRecalculation());
// resets the EngineId flag to zero
wb.setForceFormulaRecalculation(true);
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());
} finally {
wb.close();
}
}
Aggregations