コード例 #1
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);
  }
コード例 #2
0
  protected SFont createZssFont(Font poiFont) {
    SFont font = book.createFont(true);
    // font
    font.setName(poiFont.getFontName());
    font.setBoldweight(PoiEnumConversion.toBoldweight(poiFont.getBoldweight()));
    font.setItalic(poiFont.getItalic());
    font.setStrikeout(poiFont.getStrikeout());
    font.setUnderline(PoiEnumConversion.toUnderline(poiFont.getUnderline()));

    font.setHeightPoints(poiFont.getFontHeightInPoints());
    font.setTypeOffset(PoiEnumConversion.toTypeOffset(poiFont.getTypeOffset()));
    font.setColor(book.createColor(BookHelper.getFontHTMLColor(workbook, poiFont)));

    return font;
  }
コード例 #3
0
  @Test
  public void richTextTest() {
    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);

    File temp = Setup.getTempFile("pdfExportTest", ".pdf");

    exportBook(book, temp);

    Util.open(temp);
  }
コード例 #4
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);
  }
コード例 #5
0
  protected SCellStyle importCellStyle(CellStyle poiCellStyle, boolean inStyleTable) {
    SCellStyle cellStyle = null;
    //		short idx = poiCellStyle.getIndex(); // ZSS-685
    if ((cellStyle = importedStyle.get(poiCellStyle)) == null) { // ZSS-685
      cellStyle = book.createCellStyle(inStyleTable);
      importedStyle.put(poiCellStyle, cellStyle); // ZSS-685
      String dataFormat = poiCellStyle.getRawDataFormatString();
      if (dataFormat == null) { // just in case
        dataFormat = SCellStyle.FORMAT_GENERAL;
      }
      if (!poiCellStyle.isBuiltinDataFormat()) {
        cellStyle.setDirectDataFormat(dataFormat);
      } else {
        cellStyle.setDataFormat(dataFormat);
      }
      cellStyle.setWrapText(poiCellStyle.getWrapText());
      cellStyle.setLocked(poiCellStyle.getLocked());
      cellStyle.setAlignment(PoiEnumConversion.toHorizontalAlignment(poiCellStyle.getAlignment()));
      cellStyle.setVerticalAlignment(
          PoiEnumConversion.toVerticalAlignment(poiCellStyle.getVerticalAlignment()));
      cellStyle.setRotation(poiCellStyle.getRotation()); // ZSS-918
      cellStyle.setIndention(poiCellStyle.getIndention()); // ZSS-915
      Color fgColor = poiCellStyle.getFillForegroundColorColor();
      Color bgColor = poiCellStyle.getFillBackgroundColorColor();
      //			if (fgColor == null && bgColor != null) { //ZSS-797
      //				fgColor = bgColor;
      //			}
      // ZSS-857: SOLID pattern: switch fillColor and backColor
      cellStyle.setFillPattern(PoiEnumConversion.toFillPattern(poiCellStyle.getFillPattern()));
      SColor fgSColor = book.createColor(BookHelper.colorToForegroundHTML(workbook, fgColor));
      SColor bgSColor = book.createColor(BookHelper.colorToBackgroundHTML(workbook, bgColor));
      if (cellStyle.getFillPattern() == FillPattern.SOLID) {
        SColor tmp = fgSColor;
        fgSColor = bgSColor;
        bgSColor = tmp;
      }
      cellStyle.setFillColor(fgSColor);
      cellStyle.setBackColor(bgSColor); // ZSS-780

      cellStyle.setBorderLeft(PoiEnumConversion.toBorderType(poiCellStyle.getBorderLeft()));
      cellStyle.setBorderTop(PoiEnumConversion.toBorderType(poiCellStyle.getBorderTop()));
      cellStyle.setBorderRight(PoiEnumConversion.toBorderType(poiCellStyle.getBorderRight()));
      cellStyle.setBorderBottom(PoiEnumConversion.toBorderType(poiCellStyle.getBorderBottom()));

      cellStyle.setBorderLeftColor(
          book.createColor(
              BookHelper.colorToBorderHTML(workbook, poiCellStyle.getLeftBorderColorColor())));
      cellStyle.setBorderTopColor(
          book.createColor(
              BookHelper.colorToBorderHTML(workbook, poiCellStyle.getTopBorderColorColor())));
      cellStyle.setBorderRightColor(
          book.createColor(
              BookHelper.colorToBorderHTML(workbook, poiCellStyle.getRightBorderColorColor())));
      cellStyle.setBorderBottomColor(
          book.createColor(
              BookHelper.colorToBorderHTML(workbook, poiCellStyle.getBottomBorderColorColor())));
      cellStyle.setHidden(poiCellStyle.getHidden());
      // same style always use same font
      cellStyle.setFont(importFont(poiCellStyle));
    }

    return cellStyle;
  }