Esempio n. 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;
    }
  }
Esempio n. 2
0
  private void checkWorkbookBack(HSSFWorkbook wb) {
    HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
    assertNotNull(wbBack);

    HSSFSheet sheetBack = wbBack.getSheetAt(0);
    assertNotNull(sheetBack);

    HSSFPatriarch patriarchBack = sheetBack.getDrawingPatriarch();
    assertNotNull(patriarchBack);

    List<HSSFShape> children = patriarchBack.getChildren();
    assertEquals(4, children.size());
    HSSFShape hssfShape = children.get(0);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    HSSFAnchor anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(0, anchor.getDx1());
    assertEquals(512, anchor.getDx2());
    assertEquals(0, anchor.getDy1());
    assertEquals(100, anchor.getDy2());
    HSSFClientAnchor cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(1, cAnchor.getCol1());
    assertEquals(1, cAnchor.getCol2());
    assertEquals(1, cAnchor.getRow1());
    assertEquals(1, cAnchor.getRow2());

    hssfShape = children.get(1);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(512, anchor.getDx1());
    assertEquals(1024, anchor.getDx2());
    assertEquals(0, anchor.getDy1());
    assertEquals(100, anchor.getDy2());
    cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(1, cAnchor.getCol1());
    assertEquals(1, cAnchor.getCol2());
    assertEquals(1, cAnchor.getRow1());
    assertEquals(1, cAnchor.getRow2());

    hssfShape = children.get(2);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(0, anchor.getDx1());
    assertEquals(512, anchor.getDx2());
    assertEquals(0, anchor.getDy1());
    assertEquals(100, anchor.getDy2());
    cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(2, cAnchor.getCol1());
    assertEquals(2, cAnchor.getCol2());
    assertEquals(2, cAnchor.getRow1());
    assertEquals(2, cAnchor.getRow2());

    hssfShape = children.get(3);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(0, anchor.getDx1());
    assertEquals(512, anchor.getDx2());
    assertEquals(100, anchor.getDy1());
    assertEquals(200, anchor.getDy2());
    cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(2, cAnchor.getCol1());
    assertEquals(2, cAnchor.getCol2());
    assertEquals(2, cAnchor.getRow1());
    assertEquals(2, cAnchor.getRow2());
  }