Esempio n. 1
0
  @Test
  public void testSetStyle() {
    SBook book = SBooks.createBook("book1");
    SSheet sheet1 = book.createSheet("Sheet1");
    SCellStyle style1 = book.createCellStyle(true);

    SRanges.range(sheet1, "A1:B2").setCellStyle(style1);
    Assert.assertEquals(style1, SRanges.range(sheet1, "A1").getCellStyle());
    Assert.assertEquals(style1, SRanges.range(sheet1, "A2").getCellStyle());
    Assert.assertEquals(style1, SRanges.range(sheet1, "B1").getCellStyle());
    Assert.assertEquals(style1, SRanges.range(sheet1, "B2").getCellStyle());
    Assert.assertEquals(book.getDefaultCellStyle(), SRanges.range(sheet1, "C1").getCellStyle());
    Assert.assertEquals(book.getDefaultCellStyle(), SRanges.range(sheet1, "C2").getCellStyle());
  }
Esempio n. 2
0
  @Test
  @Ignore("incomplete")
  public void bookCreatedInRuntimeTest() {

    SBook book = SBooks.createBook("book1");

    SSheet sheet1 = book.createSheet("Sheet1");
    SCell cell1 = sheet1.getCell(1, 1);
    SCell cell2 = sheet1.getCell(1, 2);
    SCell cell3 = sheet1.getCell(1, 3);

    cell1.setStringValue("hair");
    cell2.setStringValue("dot");
    cell3.setStringValue("dash");

    SCellStyle style1 = book.createCellStyle(true);
    style1.setBorderBottom(BorderType.HAIR);
    cell1.setCellStyle(style1);

    SCellStyle style2 = book.createCellStyle(true);
    style2.setBorderBottom(BorderType.DOTTED);
    cell2.setCellStyle(style2);

    SCellStyle style3 = book.createCellStyle(true);
    style3.setBorderBottom(BorderType.DASHED);
    cell3.setCellStyle(style3);

    SCell cell21 = sheet1.getCell(2, 1);
    SCell cell22 = sheet1.getCell(2, 2);
    SCell cell23 = sheet1.getCell(2, 3);

    SCellStyle style21 = book.createCellStyle(true);
    style21.setBorderTop(BorderType.NONE);
    cell21.setCellStyle(style21);
    SCellStyle style22 = book.createCellStyle(true);
    style22.setBorderTop(BorderType.NONE);
    cell22.setCellStyle(style22);
    SCellStyle style23 = book.createCellStyle(true);
    style23.setBorderTop(BorderType.NONE);
    cell23.setCellStyle(style23);

    // File file = ImExpTestUtil.write(book);

    // FIXME assert it
    // confirm
    // cellBorderTest(inBook);
  }
  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;
  }