Search in sources :

Example 1 with CTWorkbook

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook 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;
}
Also used : CTCalcPr(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr) CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook)

Example 2 with CTWorkbook

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook in project poi by apache.

the class XSSFWorkbook method saveNamedRanges.

/**
     * marshal named ranges from the {@link #namedRanges} collection to the underlying CTWorkbook bean
     */
private void saveNamedRanges() {
    // Named ranges
    if (namedRanges.size() > 0) {
        CTDefinedNames names = CTDefinedNames.Factory.newInstance();
        CTDefinedName[] nr = new CTDefinedName[namedRanges.size()];
        int i = 0;
        for (XSSFName name : namedRanges) {
            nr[i] = name.getCTName();
            i++;
        }
        names.setDefinedNameArray(nr);
        if (workbook.isSetDefinedNames()) {
            workbook.unsetDefinedNames();
        }
        workbook.setDefinedNames(names);
        // Re-process the named ranges
        reprocessNamedRanges();
    } else {
        if (workbook.isSetDefinedNames()) {
            workbook.unsetDefinedNames();
        }
    }
}
Also used : CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName) CTDefinedNames(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames)

Example 3 with CTWorkbook

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook in project poi by apache.

the class TestXSSFWorkbook method testAddPivotCache.

@Test
public void testAddPivotCache() throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook();
    try {
        CTWorkbook ctWb = wb.getCTWorkbook();
        CTPivotCache pivotCache = wb.addPivotCache("0");
        //Ensures that pivotCaches is initiated
        assertTrue(ctWb.isSetPivotCaches());
        assertSame(pivotCache, ctWb.getPivotCaches().getPivotCacheArray(0));
        assertEquals("0", pivotCache.getId());
    } finally {
        wb.close();
    }
}
Also used : CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook) CTPivotCache(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache) Test(org.junit.Test)

Example 4 with CTWorkbook

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook in project poi by apache.

the class XSSFWorkbook method addPivotCache.

/**
     * Add pivotCache to the workbook
     */
@Beta
protected CTPivotCache addPivotCache(String rId) {
    CTWorkbook ctWorkbook = getCTWorkbook();
    CTPivotCaches caches;
    if (ctWorkbook.isSetPivotCaches()) {
        caches = ctWorkbook.getPivotCaches();
    } else {
        caches = ctWorkbook.addNewPivotCaches();
    }
    CTPivotCache cache = caches.addNewPivotCache();
    int tableId = getPivotTables().size() + 1;
    cache.setCacheId(tableId);
    cache.setId(rId);
    if (pivotCaches == null) {
        pivotCaches = new ArrayList<CTPivotCache>();
    }
    pivotCaches.add(cache);
    return cache;
}
Also used : CTPivotCaches(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCaches) CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook) CTPivotCache(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache) Beta(org.apache.poi.util.Beta)

Example 5 with CTWorkbook

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook 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);
    }
}
Also used : CTCalcPr(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr) CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook)

Aggregations

CTWorkbook (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook)5 CTCalcPr (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr)3 Test (org.junit.Test)2 CTPivotCache (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache)2 POIXMLProperties (org.apache.poi.POIXMLProperties)1 Beta (org.apache.poi.util.Beta)1 CTBookView (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView)1 CTBookViews (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews)1 CTDefinedName (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName)1 CTDefinedNames (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames)1 CTPivotCaches (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCaches)1 CTWorkbookPr (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr)1