Search in sources :

Example 16 with InternalWorkbook

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);
}
Also used : RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook)

Example 17 with InternalWorkbook

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;
}
Also used : ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook)

Example 18 with InternalWorkbook

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);
}
Also used : InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherBlipRecord(org.apache.poi.ddf.EscherBlipRecord)

Aggregations

InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)18 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)5 Test (org.junit.Test)5 NameRecord (org.apache.poi.hssf.record.NameRecord)4 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)3 InternalSheet (org.apache.poi.hssf.model.InternalSheet)3 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)3 Ptg (org.apache.poi.ss.formula.ptg.Ptg)3 AutoFilterInfoRecord (org.apache.poi.hssf.record.AutoFilterInfoRecord)2 RecalcIdRecord (org.apache.poi.hssf.record.RecalcIdRecord)2 HSSFEvaluationWorkbook (org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)2 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 BackupRecord (org.apache.poi.hssf.record.BackupRecord)1 CommonObjectDataSubRecord (org.apache.poi.hssf.record.CommonObjectDataSubRecord)1 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)1 ExtendedFormatRecord (org.apache.poi.hssf.record.ExtendedFormatRecord)1