コード例 #1
0
 @Test
 public void autoFilter() {
   File outFile =
       ImExpTestUtil.write(
           ImExpTestUtil.loadBook(FILTER_IMPORT_FILE_UNDER_TEST, "XSSFBook"), EXPORTER_TYPE);
   SBook book = ImExpTestUtil.loadBook(outFile, DEFAULT_BOOK_NAME);
   autoFilter(book);
 }
コード例 #2
0
 @Test
 public void cellBorderTest() {
   File outFile =
       ImExpTestUtil.write(
           ImExpTestUtil.loadBook(IMPORT_FILE_UNDER_TEST, "XSSFBook"), EXPORTER_TYPE);
   SBook book = ImExpTestUtil.loadBook(outFile, DEFAULT_BOOK_NAME);
   cellBorderTest(book);
 }
コード例 #3
0
 @Test
 public void scatterChart() {
   File outFile =
       ImExpTestUtil.write(
           ImExpTestUtil.loadBook(CHART_IMPORT_FILE_UNDER_TEST, "XSSFBook"), EXPORTER_TYPE);
   SBook book = ImExpTestUtil.loadBook(outFile, DEFAULT_BOOK_NAME);
   scatterChart(book);
 }
コード例 #4
0
 @Test
 public void lastChangedColumnTest() {
   File outFile =
       ImExpTestUtil.write(
           ImExpTestUtil.loadBook(IMPORT_FILE_UNDER_TEST, "XSSFBook"), EXPORTER_TYPE);
   SBook book = ImExpTestUtil.loadBook(outFile, DEFAULT_BOOK_NAME);
   lastChangedColumnTest(book);
 }
コード例 #5
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());
  }
コード例 #6
0
  @Test
  public void richTextModelTest() {
    SBook book = SBooks.createBook("rich");
    SSheet sheet = book.createSheet("first");
    SCell cell = sheet.getCell(0, 0);

    SRichText rText = cell.setupRichTextValue();
    SFont font1 = book.createFont(true);
    font1.setColor(book.createColor("#0000FF"));
    font1.setStrikeout(true);
    rText.addSegment("abc", font1);

    SFont font2 = book.createFont(true);
    font2.setColor(book.createColor("#FF0000"));
    font2.setBoldweight(Boldweight.BOLD);
    rText.addSegment("123", font2);

    SFont font3 = book.createFont(true);
    font3.setColor(book.createColor("#C78548"));
    font3.setUnderline(Underline.SINGLE);
    rText.addSegment("xyz", font3);

    cell = sheet.getCell(0, 1);
    rText = cell.setupRichTextValue();
    font1 = book.createFont(true);
    font1.setColor(book.createColor("#FFFF00"));
    font1.setItalic(true);
    rText.addSegment("Hello", font1);

    font2 = book.createFont(true);
    font2.setColor(book.createColor("#FF33FF"));
    font2.setBoldweight(Boldweight.BOLD);
    rText.addSegment("World", font2);

    font3 = book.createFont(true);
    font3.setColor(book.createColor("#CCCC99"));
    font3.setName("HGPSoeiKakupoptai");
    rText.addSegment("000", font3);

    ImExpTestUtil.write(book, ExcelExportFactory.Type.XLSX);
  }
コード例 #7
0
  @SuppressWarnings("unused")
  @Test
  public void hyperlinkModelTest() {
    SBook book = SBooks.createBook("hyperlink");
    SSheet sheet = book.createSheet("link");
    SCell cell = sheet.getCell(0, 0);
    SHyperlink hyperlink =
        cell.setupHyperlink(
            SHyperlink.HyperlinkType.URL,
            "http://www.zkoss.org/download/zkspreadsheet",
            "Download ZK Spreadsheet");

    cell.setStringValue("Go to ZK Spreadsheet Download Page");

    SCell cellB4 = sheet.getCell("B4");

    SRichText rText = cellB4.setupRichTextValue();
    SFont font1 = book.createFont(true);
    font1.setColor(book.createColor("#0000FF"));
    font1.setStrikeout(true);
    rText.addSegment("abc", font1);

    SFont font2 = book.createFont(true);
    font2.setColor(book.createColor("#FF0000"));
    font2.setBoldweight(Boldweight.BOLD);
    rText.addSegment("123", font2);

    SFont font3 = book.createFont(true);
    font3.setColor(book.createColor("#C78548"));
    font3.setUnderline(Underline.SINGLE);
    rText.addSegment("xyz", font3);

    SHyperlink linkB4 =
        cellB4.setupHyperlink(
            SHyperlink.HyperlinkType.URL, "http://www.yahoo.com.tw/", "Hyperlink Label B4");

    ImExpTestUtil.write(book, ExcelExportFactory.Type.XLSX);
  }
コード例 #8
0
  @Test
  public void exportWidthSplitTest() {
    SBook book = SBooks.createBook("book1");
    SSheet sheet1 = book.createSheet("Sheet1");
    int defaultWidth = 100;
    sheet1.setDefaultColumnWidth(defaultWidth);
    sheet1.setDefaultRowHeight(200);
    Assert.assertEquals(defaultWidth, sheet1.getDefaultColumnWidth());
    Assert.assertEquals(200, sheet1.getDefaultRowHeight());

    Iterator<SColumnArray> arrays = sheet1.getColumnArrayIterator();
    Assert.assertFalse(arrays.hasNext());

    Assert.assertNull(sheet1.getColumnArray(0));

    sheet1.setupColumnArray(0, 8).setWidth(10);
    sheet1.setupColumnArray(11, 255);
    arrays = sheet1.getColumnArrayIterator();
    SColumnArray array = arrays.next();
    Assert.assertEquals(0, array.getIndex());
    Assert.assertEquals(8, array.getLastIndex());
    Assert.assertEquals(10, array.getWidth());

    array = arrays.next();
    Assert.assertEquals(9, array.getIndex());
    Assert.assertEquals(10, array.getLastIndex());
    Assert.assertEquals(defaultWidth, array.getWidth());

    array = arrays.next();
    Assert.assertEquals(11, array.getIndex());
    Assert.assertEquals(255, array.getLastIndex());
    Assert.assertEquals(defaultWidth, array.getWidth());

    ///////////// first export
    File outFile =
        ImExpTestUtil.writeBookToFile(
            book,
            ImExpTestUtil.DEFAULT_EXPORT_TARGET_PATH + ImExpTestUtil.DEFAULT_EXPORT_FILE_NAME_XLSX,
            EXPORTER_TYPE);
    SBook outBook = ImExpTestUtil.loadBook(outFile, "OutBook");

    sheet1 = outBook.getSheet(0);

    // default width become 104px
    // Assert.assertEquals(defaultWidth, sheet1.getDefaultColumnWidth());
    Assert.assertEquals(200, sheet1.getDefaultRowHeight());

    arrays = sheet1.getColumnArrayIterator();
    Assert.assertTrue(arrays.hasNext());

    arrays = sheet1.getColumnArrayIterator();
    array = arrays.next();
    Assert.assertEquals(0, array.getIndex());
    Assert.assertEquals(8, array.getLastIndex());
    Assert.assertEquals(10, array.getWidth());

    array = arrays.next();
    Assert.assertEquals(9, array.getIndex());
    Assert.assertEquals(10, array.getLastIndex());
    Assert.assertEquals(defaultWidth, array.getWidth());

    array = arrays.next();
    Assert.assertEquals(11, array.getIndex());
    Assert.assertEquals(255, array.getLastIndex());
    Assert.assertEquals(defaultWidth, array.getWidth());

    ///////////// second export
    File outFile2 =
        ImExpTestUtil.writeBookToFile(
            outBook,
            ImExpTestUtil.DEFAULT_EXPORT_TARGET_PATH + ImExpTestUtil.DEFAULT_EXPORT_FILE_NAME_XLSX,
            EXPORTER_TYPE);
    SBook outBook2 = ImExpTestUtil.loadBook(outFile2, "OutBook");

    sheet1 = outBook2.getSheet(0);

    // default width become 104px
    // Assert.assertEquals(100, sheet1.getDefaultColumnWidth());
    Assert.assertEquals(200, sheet1.getDefaultRowHeight());

    arrays = sheet1.getColumnArrayIterator();
    Assert.assertTrue(arrays.hasNext());

    arrays = sheet1.getColumnArrayIterator();
    array = arrays.next();
    Assert.assertEquals(0, array.getIndex());
    Assert.assertEquals(8, array.getLastIndex());
    Assert.assertEquals(10, array.getWidth());

    array = arrays.next();
    Assert.assertEquals(9, array.getIndex());
    Assert.assertEquals(10, array.getLastIndex());
    Assert.assertEquals(100, array.getWidth());

    array = arrays.next();
    Assert.assertEquals(11, array.getIndex());
    Assert.assertEquals(255, array.getLastIndex());
    Assert.assertEquals(100, array.getWidth());
  }
コード例 #9
0
 @Test
 public void export4HumanChecking() {
   SBook book = ImExpTestUtil.loadBook(IMPORT_FILE_UNDER_TEST, "XSSFBook");
   ImExpTestUtil.writeBookToFile(
       book, ImExpTestUtil.DEFAULT_EXPORT_TARGET_PATH + "humanChecking.xlsx", EXPORTER_TYPE);
 }