org.apache.poi.hssf.usermodel.HSSFSheet.getWorkbook()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.apache.poi.hssf.usermodel.HSSFSheet.getWorkbook()方法的一些代码示例,展示了HSSFSheet.getWorkbook()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFSheet.getWorkbook()方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFSheet
类名称:HSSFSheet
方法名:getWorkbook

HSSFSheet.getWorkbook介绍

[英]Return the parent workbook
[中]返回父工作簿

代码示例

代码示例来源:origin: org.apache.poi/poi

protected HSSFConditionalFormattingThreshold(Threshold threshold, HSSFSheet sheet) {
  this.threshold = threshold;
  this.sheet = sheet;
  this.workbook = sheet.getWorkbook();
}
protected Threshold getThreshold() {

代码示例来源:origin: org.apache.poi/poi

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;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * 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);
}

代码示例来源:origin: org.apache.poi/poi

/**
 * 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);
}

代码示例来源:origin: org.apache.poi/poi

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

代码示例来源:origin: org.apache.poi/poi

/**
 * @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));
}

代码示例来源:origin: org.apache.poi/poi

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

代码示例来源:origin: org.apache.poi/poi

@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;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * @return new unique shapeId
 */
int newShapeId() {
  DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager();
  EscherDgRecord dg =
      _boundAggregate.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
  return dm.allocateShapeId(dg);
}

代码示例来源:origin: org.apache.poi/poi

/**
 * 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);
}

代码示例来源:origin: org.apache.poi/poi

void afterCreate() {
  DrawingManager2 drawingManager = _sheet.getWorkbook().getWorkbook().getDrawingManager();
  short dgId = drawingManager.findNewDrawingGroupId();
  _boundAggregate.setDgId(dgId);
  _boundAggregate.setMainSpRecordId(newShapeId());
  drawingManager.incrementDrawingsSaved();
}

代码示例来源:origin: org.apache.poi/poi

/**
 * 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);
}

代码示例来源:origin: org.apache.poi/poi

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

代码示例来源:origin: org.apache.poi/poi

@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);
}

代码示例来源:origin: org.apache.poi/poi

@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);
  }
}

代码示例来源:origin: org.apache.poi/poi

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

代码示例来源:origin: org.apache.poi/poi

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

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
   * 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);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

void afterCreate() {
  DrawingManager2 drawingManager = _sheet.getWorkbook().getWorkbook().getDrawingManager();
  short dgId = drawingManager.findNewDrawingGroupId();
  _boundAggregate.setDgId(dgId);
  _boundAggregate.setMainSpRecordId(newShapeId());
  drawingManager.incrementDrawingsSaved();
}

代码示例来源:origin: com.haulmont.thirdparty/poi

/**
 * 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);
}

相关文章

微信公众号

最新文章

更多

HSSFSheet类方法