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;
}
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();
}
}
}
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();
}
}
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;
}
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);
}
}
Aggregations