示例#1
0
  @Test
  public void movePicture() {
    SBook book = SBooks.createBook("book1");
    SSheet sheet = book.createSheet("Picture");

    assertEquals(0, sheet.getPictures().size());

    try {
      AImage zklogo = new AImage(RangeTest.class.getResource("zklogo.png"));

      ViewAnchor anchor = new ViewAnchor(0, 1, zklogo.getWidth() / 2, zklogo.getHeight() / 2);
      SPicture picture =
          SRanges.range(sheet).addPicture(anchor, zklogo.getByteData(), SPicture.Format.PNG);

      assertEquals(1, sheet.getPictures().size());
      assertEquals(Format.PNG, picture.getFormat());
      assertEquals(zklogo.getWidth() / 2, picture.getAnchor().getWidth());

      ViewAnchor newAnchor = new ViewAnchor(3, 4, zklogo.getWidth() / 2, zklogo.getHeight() / 2);
      SRanges.range(sheet).movePicture(picture, newAnchor);
      assertEquals(3, picture.getAnchor().getRowIndex());
      assertEquals(4, picture.getAnchor().getColumnIndex());

      //			ImExpTestUtil.write(book, Type.XLSX); //human checking
    } catch (IOException e) {
      e.printStackTrace();
      fail();
    }
  }
 protected void importPicture(List<Picture> poiPictures, Sheet poiSheet, SSheet sheet) {
   for (Picture poiPicture : poiPictures) {
     PictureData poiPicData = poiPicture.getPictureData();
     Integer picDataIx = importedPictureData.get(poiPicData); // ZSS-735
     if (picDataIx != null) {
       sheet.addPicture(
           picDataIx.intValue(), toViewAnchor(poiSheet, poiPicture.getClientAnchor()));
     } else {
       Format format = Format.valueOfFileExtension(poiPicData.suggestFileExtension());
       if (format != null) {
         SPicture pic =
             sheet.addPicture(
                 format,
                 poiPicData.getData(),
                 toViewAnchor(poiSheet, poiPicture.getClientAnchor()));
         importedPictureData.put(poiPicData, pic.getPictureData().getIndex());
       } else {
         // TODO log we ignore a picture with unsupported format
       }
     }
   }
 }
示例#3
0
  @Test
  public void picture() {
    File outFile =
        ImExpTestUtil.write(
            ImExpTestUtil.loadBook(PICTURE_IMPORT_FILE_UNDER_TEST, "XSSFBook"), EXPORTER_TYPE);
    SBook book = ImExpTestUtil.loadBook(outFile, DEFAULT_BOOK_NAME);
    picture(book);

    SSheet sheet2 = book.getSheet(1);
    assertEquals(2, sheet2.getPictures().size());
    SPicture flowerJpg = sheet2.getPicture(0);
    assertEquals(Format.JPG, flowerJpg.getFormat());
    assertEquals(569, flowerJpg.getAnchor().getWidth());
    assertEquals(427, flowerJpg.getAnchor().getHeight());

    // different spec in XLS
    SPicture rainbowGif = sheet2.getPicture(1);
    assertEquals(Format.GIF, rainbowGif.getFormat());
    assertEquals(613, rainbowGif.getAnchor().getWidth());
    assertEquals(345, rainbowGif.getAnchor().getHeight());
  }