Search in sources :

Example 1 with RecalcIdRecord

use of org.apache.poi.hssf.record.RecalcIdRecord in project poi by apache.

the class HSSFWorkbook method getForceFormulaRecalculation.

/**
     * Whether Excel will be asked to recalculate all formulas when the  workbook is opened.
     *
     * @since 3.8
     */
@Override
public boolean getForceFormulaRecalculation() {
    InternalWorkbook iwb = getWorkbook();
    RecalcIdRecord recalc = (RecalcIdRecord) iwb.findFirstRecordBySid(RecalcIdRecord.sid);
    return recalc != null && recalc.getEngineId() != 0;
}
Also used : RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook)

Example 2 with RecalcIdRecord

use of org.apache.poi.hssf.record.RecalcIdRecord in project poi by apache.

the class InternalWorkbook method getRecalcId.

/**
     * Get or create RecalcIdRecord
     *
     * @return a new RecalcIdRecord
     *
     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#setForceFormulaRecalculation(boolean)
     */
public RecalcIdRecord getRecalcId() {
    RecalcIdRecord record = (RecalcIdRecord) findFirstRecordBySid(RecalcIdRecord.sid);
    if (record == null) {
        record = new RecalcIdRecord();
        // typically goes after the Country record
        int pos = findFirstRecordLocBySid(CountryRecord.sid);
        records.add(pos + 1, record);
    }
    return record;
}
Also used : RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord)

Example 3 with RecalcIdRecord

use of org.apache.poi.hssf.record.RecalcIdRecord in project poi by apache.

the class HSSFWorkbook 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) {
    InternalWorkbook iwb = getWorkbook();
    RecalcIdRecord recalc = iwb.getRecalcId();
    recalc.setEngineId(0);
}
Also used : RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook)

Example 4 with RecalcIdRecord

use of org.apache.poi.hssf.record.RecalcIdRecord in project poi by apache.

the class TestWorkbook method testRecalcId.

@Test
public void testRecalcId() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    assertFalse(wb.getForceFormulaRecalculation());
    InternalWorkbook iwb = TestHSSFWorkbook.getInternalWorkbook(wb);
    int countryPos = iwb.findFirstRecordLocBySid(CountryRecord.sid);
    assertTrue(countryPos != -1);
    // RecalcIdRecord is not present in new workbooks
    assertEquals(null, iwb.findFirstRecordBySid(RecalcIdRecord.sid));
    RecalcIdRecord record = iwb.getRecalcId();
    assertNotNull(record);
    assertSame(record, iwb.getRecalcId());
    assertSame(record, iwb.findFirstRecordBySid(RecalcIdRecord.sid));
    assertEquals(countryPos + 1, iwb.findFirstRecordLocBySid(RecalcIdRecord.sid));
    record.setEngineId(100);
    assertEquals(100, record.getEngineId());
    assertTrue(wb.getForceFormulaRecalculation());
    // resets the EngineId flag to zero
    wb.setForceFormulaRecalculation(true);
    assertEquals(0, record.getEngineId());
    assertFalse(wb.getForceFormulaRecalculation());
    wb.close();
}
Also used : RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) TestHSSFWorkbook(org.apache.poi.hssf.usermodel.TestHSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

RecalcIdRecord (org.apache.poi.hssf.record.RecalcIdRecord)4 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 TestHSSFWorkbook (org.apache.poi.hssf.usermodel.TestHSSFWorkbook)1 Test (org.junit.Test)1