protected HSSFConditionalFormattingThreshold(Threshold threshold, HSSFSheet sheet) { this.threshold = threshold; this.sheet = sheet; this.workbook = sheet.getWorkbook(); } protected Threshold getThreshold() {
HSSFConditionalFormattingRule(HSSFSheet pSheet, CFRuleBase pRuleRecord) { if (pSheet == null) { throw new IllegalArgumentException("pSheet must not be null"); } if (pRuleRecord == null) { throw new IllegalArgumentException("pRuleRecord must not be null"); } sheet = pSheet; workbook = pSheet.getWorkbook(); cfRuleRecord = pRuleRecord; }
/** * TODO - parse conditional format formulas properly i.e. produce tRefN and tAreaN instead of tRef and tArea * this call will produce the wrong results if the formula contains any cell references * One approach might be to apply the inverse of SharedFormulaRecord.convertSharedFormulas(Stack, int, int) * Note - two extra parameters (rowIx & colIx) will be required. They probably come from one of the Region objects. * * @param formula The formula to parse, excluding the leading equals sign. * @param sheet The sheet that the formula is on. * @return <code>null</code> if <tt>formula</tt> was null. */ public static Ptg[] parseFormula(String formula, HSSFSheet sheet) { if(formula == null) { return null; } int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet); return HSSFFormulaParser.parse(formula, sheet.getWorkbook(), FormulaType.CELL, sheetIndex); }
/** * Returns the name of this sheet * * @return the name of this sheet */ @SuppressWarnings("resource") @Override public String getSheetName() { HSSFWorkbook wb = getWorkbook(); int idx = wb.getSheetIndex(this); return wb.getSheetName(idx); }
@SuppressWarnings("resource") private Ptg[] createListFormula(HSSFSheet sheet) { if (_explicitListValues == null) { HSSFWorkbook wb = sheet.getWorkbook(); // formula is parsed with slightly different RVA rules: (root node type must be 'reference') return HSSFFormulaParser.parse(_formula1, wb, FormulaType.DATAVALIDATION_LIST, wb.getSheetIndex(sheet)); // To do: Excel places restrictions on the available operations within a list formula. // Some things like union and intersection are not allowed. } // explicit list was provided StringBuilder sb = new StringBuilder(_explicitListValues.length * 16); for (int i = 0; i < _explicitListValues.length; i++) { if (i > 0) { sb.append('\0'); // list delimiter is the nul char } sb.append(_explicitListValues[i]); } return new Ptg[] { new StringPtg(sb.toString()), }; }
/** * @return The parsed token array representing the formula or value specified. * Empty array if both formula and value are <code>null</code> */ @SuppressWarnings("resource") private static Ptg[] convertDoubleFormula(String formula, Double value, HSSFSheet sheet) { if (formula == null) { if (value == null) { return Ptg.EMPTY_PTG_ARRAY; } return new Ptg[] { new NumberPtg(value.doubleValue()), }; } if (value != null) { throw new IllegalStateException("Both formula and value cannot be present"); } HSSFWorkbook wb = sheet.getWorkbook(); return HSSFFormulaParser.parse(formula, wb, FormulaType.CELL, wb.getSheetIndex(sheet)); }
/** * create shape tree from existing escher records tree */ void buildShapeTree() { EscherContainerRecord dgContainer = _boundAggregate.getEscherContainer(); if (dgContainer == null) { return; } EscherContainerRecord spgrConrainer = dgContainer.getChildContainers().get(0); List<EscherContainerRecord> spgrChildren = spgrConrainer.getChildContainers(); for (int i = 0; i < spgrChildren.size(); i++) { EscherContainerRecord spContainer = spgrChildren.get(i); if (i != 0) { HSSFShapeFactory.createShapeTree(spContainer, _boundAggregate, this, _sheet.getWorkbook().getDirectory()); } } }
@Override public List<HSSFDataValidation> getDataValidations() { DataValidityTable dvt = _sheet.getOrCreateDataValidityTable(); final List<HSSFDataValidation> hssfValidations = new ArrayList<>(); RecordVisitor visitor = new RecordVisitor() { private HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(getWorkbook()); @Override public void visitRecord(Record r) { if (!(r instanceof DVRecord)) { return; } DVRecord dvRecord = (DVRecord) r; CellRangeAddressList regions = dvRecord.getCellRangeAddress().copy(); DVConstraint constraint = DVConstraint.createDVConstraint(dvRecord, book); HSSFDataValidation hssfDataValidation = new HSSFDataValidation(regions, constraint); hssfDataValidation.setErrorStyle(dvRecord.getErrorStyle()); hssfDataValidation.setEmptyCellAllowed(dvRecord.getEmptyCellAllowed()); hssfDataValidation.setSuppressDropDownArrow(dvRecord.getSuppressDropdownArrow()); hssfDataValidation.createPromptBox(dvRecord.getPromptTitle(), dvRecord.getPromptText()); hssfDataValidation.setShowPromptBox(dvRecord.getShowPromptOnCellSelected()); hssfDataValidation.createErrorBox(dvRecord.getErrorTitle(), dvRecord.getErrorText()); hssfDataValidation.setShowErrorBox(dvRecord.getShowErrorOnInvalidValue()); hssfValidations.add(hssfDataValidation); } }; dvt.visitContainedRecords(visitor); return hssfValidations; }
/** * @return new unique shapeId */ int newShapeId() { DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager(); EscherDgRecord dg = _boundAggregate.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID); return dm.allocateShapeId(dg); }
/** * Return the dimension of the embedded image in pixel * * @return image dimension in pixels */ @Override public Dimension getImageDimension(){ InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook(); EscherBSERecord bse = iwb.getBSERecord(getPictureIndex()); byte[] data = bse.getBlipRecord().getPicturedata(); int type = bse.getBlipTypeWin32(); return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type); }
void afterCreate() { DrawingManager2 drawingManager = _sheet.getWorkbook().getWorkbook().getDrawingManager(); short dgId = drawingManager.findNewDrawingGroupId(); _boundAggregate.setDgId(dgId); _boundAggregate.setMainSpRecordId(newShapeId()); drawingManager.incrementDrawingsSaved(); }
/** * 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); }
public void setBackgroundImage(int pictureIndex){ setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__PATTERNTEXTURE, false, true, pictureIndex)); setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, false, false, FILL_TYPE_PICTURE)); EscherBSERecord bse = getPatriarch().getSheet().getWorkbook().getWorkbook().getBSERecord(pictureIndex); bse.setRef(bse.getRef() + 1); }
@Override void afterInsert(HSSFPatriarch patriarch) { EscherAggregate agg = patriarch.getBoundAggregate(); agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); EscherBSERecord bse = patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); bse.setRef(bse.getRef() + 1); }
@Override void afterInsert(HSSFPatriarch patriarch) { EscherAggregate agg = patriarch.getBoundAggregate(); agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); if(getPictureIndex() != -1) { EscherBSERecord bse = patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); bse.setRef(bse.getRef() + 1); } }
public void resetBackgroundImage(){ EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.FILL__PATTERNTEXTURE); if (null != property){ EscherBSERecord bse = getPatriarch().getSheet().getWorkbook().getWorkbook().getBSERecord(property.getPropertyValue()); bse.setRef(bse.getRef() - 1); getOptRecord().removeEscherProperty(EscherProperties.FILL__PATTERNTEXTURE); } setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, false, false, FILL_TYPE_SOLID)); }
HSSFPictureData pictData = getSheet().getWorkbook().getAllPictures().get(pictureIndex-1); switch (pictData.getFormat()) { case Workbook.PICTURE_TYPE_WMF: DirectoryEntry oleRoot; try { DirectoryNode dn = _sheet.getWorkbook().getDirectory(); if (dn == null) { throw new FileNotFoundException();
/** * Return picture data for this shape * * @return picture data for this shape */ public HSSFPictureData getPictureData(){ InternalWorkbook iwb = _patriarch._sheet.getWorkbook().getWorkbook(); EscherBlipRecord blipRecord = iwb.getBSERecord(_pictureIndex).getBlipRecord(); return new HSSFPictureData(blipRecord); } }
void afterCreate() { DrawingManager2 drawingManager = _sheet.getWorkbook().getWorkbook().getDrawingManager(); short dgId = drawingManager.findNewDrawingGroupId(); _boundAggregate.setDgId(dgId); _boundAggregate.setMainSpRecordId(newShapeId()); drawingManager.incrementDrawingsSaved(); }
/** * Return picture data for this shape * * @return picture data for this shape */ public HSSFPictureData getPictureData(){ InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook(); EscherBlipRecord blipRecord = iwb.getBSERecord(getPictureIndex()).getBlipRecord(); return new HSSFPictureData(blipRecord); }