示例#1
0
  /**
   * 获取Excel2003图片
   *
   * @param sheetNum 当前sheet编号
   * @param sheet 当前sheet对象
   * @param workbook 工作簿对象
   * @return Map key:图片单元格索引(0_1_1)String,value:图片流PictureData
   * @throws IOException
   */
  public static Map<String, PictureData> getSheetPictrues03(
      int sheetNum, HSSFSheet sheet, HSSFWorkbook workbook) {

    Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
    List<HSSFPictureData> pictures = workbook.getAllPictures();
    if (pictures.size() != 0) {
      for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
        HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
        if (shape instanceof HSSFPicture) {
          if (null != shape) {
            HSSFPicture pic = (HSSFPicture) shape;
            int pictureIndex = pic.getPictureIndex() - 1;
            HSSFPictureData picData = pictures.get(pictureIndex);
            String picIndex =
                String.valueOf(sheetNum)
                    + UNDER_LINE
                    + String.valueOf(anchor.getRow1())
                    + UNDER_LINE
                    + String.valueOf(anchor.getCol1());
            sheetIndexPicMap.put(picIndex, picData);
          }
        }
      }
      return sheetIndexPicMap;
    } else {
      return null;
    }
  }
示例#2
0
  public void testReadExistingImage() {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
    HSSFSheet sheet = wb.getSheet("pictures");
    HSSFPatriarch drawing = sheet.getDrawingPatriarch();
    assertEquals(1, drawing.getChildren().size());
    HSSFPicture picture = (HSSFPicture) drawing.getChildren().get(0);

    assertEquals(picture.getPictureIndex(), 2);
    assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);
    assertEquals(picture.getFillColor(), 0x5DC943);
    assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
    assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);
    assertEquals(picture.isNoFill(), false);

    picture.setPictureIndex(2);
    assertEquals(picture.getPictureIndex(), 2);
  }
示例#3
0
 public void testDefaultPictureSettings() {
   HSSFPicture picture = new HSSFPicture(null, new HSSFClientAnchor());
   assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
   assertEquals(picture.getFillColor(), HSSFShape.FILL__FILLCOLOR_DEFAULT);
   assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_NONE);
   assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);
   assertEquals(picture.isNoFill(), false);
   assertEquals(picture.getPictureIndex(), -1); // not set yet
 }
示例#4
0
  /** No NullPointerException should appear */
  public void testDefaultSettingsWithEmptyContainer() {
    EscherContainerRecord container = new EscherContainerRecord();
    EscherOptRecord opt = new EscherOptRecord();
    opt.setRecordId(EscherOptRecord.RECORD_ID);
    container.addChildRecord(opt);
    ObjRecord obj = new ObjRecord();
    CommonObjectDataSubRecord cod = new CommonObjectDataSubRecord();
    cod.setObjectType(HSSFSimpleShape.OBJECT_TYPE_PICTURE);
    obj.addSubRecord(cod);
    HSSFPicture picture = new HSSFPicture(container, obj);

    assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
    assertEquals(picture.getFillColor(), HSSFShape.FILL__FILLCOLOR_DEFAULT);
    assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);
    assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);
    assertEquals(picture.isNoFill(), HSSFShape.NO_FILL_DEFAULT);
    assertEquals(picture.getPictureIndex(), -1); // not set yet
  }