use of org.apache.poi.hssf.model.InternalWorkbook 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);
}
use of org.apache.poi.hssf.model.InternalWorkbook in project poi by apache.
the class HSSFCell method applyUserCellStyle.
/**
* Applying a user-defined style (UDS) is special. Excel does not directly reference user-defined styles, but
* instead create a 'proxy' ExtendedFormatRecord referencing the UDS as parent.
*
* The proceudre to apply a UDS is as follows:
*
* 1. search for a ExtendedFormatRecord with parentIndex == style.getIndex()
* and xfType == ExtendedFormatRecord.XF_CELL.
* 2. if not found then create a new ExtendedFormatRecord and copy all attributes from the user-defined style
* and set the parentIndex to be style.getIndex()
* 3. return the index of the ExtendedFormatRecord, this will be assigned to the parent cell record
*
* @param style the user style to apply
*
* @return the index of a ExtendedFormatRecord record that will be referenced by the cell
*/
private short applyUserCellStyle(HSSFCellStyle style) {
if (style.getUserStyleName() == null) {
throw new IllegalArgumentException("Expected user-defined style");
}
InternalWorkbook iwb = _book.getWorkbook();
short userXf = -1;
int numfmt = iwb.getNumExFormats();
for (short i = 0; i < numfmt; i++) {
ExtendedFormatRecord xf = iwb.getExFormatAt(i);
if (xf.getXFType() == ExtendedFormatRecord.XF_CELL && xf.getParentIndex() == style.getIndex()) {
userXf = i;
break;
}
}
short styleIndex;
if (userXf == -1) {
ExtendedFormatRecord xfr = iwb.createCellXF();
xfr.cloneStyleFrom(iwb.getExFormatAt(style.getIndex()));
xfr.setIndentionOptions((short) 0);
xfr.setXFType(ExtendedFormatRecord.XF_CELL);
xfr.setParentIndex(style.getIndex());
styleIndex = (short) numfmt;
} else {
styleIndex = userXf;
}
return styleIndex;
}
use of org.apache.poi.hssf.model.InternalWorkbook in project poi by apache.
the class HSSFPicture method getPictureData.
/**
* Return picture data for this shape
*
* @return picture data for this shape or {@code null} if picture wasn't embedded, i.e. external linked
*/
@Override
public HSSFPictureData getPictureData() {
int picIdx = getPictureIndex();
if (picIdx == -1) {
return null;
}
HSSFPatriarch patriarch = getPatriarch();
HSSFShape parent = getParent();
while (patriarch == null && parent != null) {
patriarch = parent.getPatriarch();
parent = parent.getParent();
}
if (patriarch == null) {
throw new IllegalStateException("Could not find a patriarch for a HSSPicture");
}
InternalWorkbook iwb = patriarch.getSheet().getWorkbook().getWorkbook();
EscherBSERecord bse = iwb.getBSERecord(picIdx);
EscherBlipRecord blipRecord = bse.getBlipRecord();
return new HSSFPictureData(blipRecord);
}
Aggregations