예제 #1
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 SCell importCell(Cell poiCell, int row, SSheet sheet) {

    SCell cell = sheet.getCell(row, poiCell.getColumnIndex());
    cell.setCellStyle(importCellStyle(poiCell.getCellStyle()));

    switch (poiCell.getCellType()) {
      case Cell.CELL_TYPE_NUMERIC:
        cell.setNumberValue(poiCell.getNumericCellValue());
        break;
      case Cell.CELL_TYPE_STRING:
        RichTextString poiRichTextString = poiCell.getRichStringCellValue();
        if (poiRichTextString != null && poiRichTextString.numFormattingRuns() > 0) {
          SRichText richText = cell.setupRichTextValue();
          importRichText(poiCell, poiRichTextString, richText);
        } else {
          cell.setStringValue(poiCell.getStringCellValue());
        }
        break;
      case Cell.CELL_TYPE_BOOLEAN:
        cell.setBooleanValue(poiCell.getBooleanCellValue());
        break;
      case Cell.CELL_TYPE_FORMULA:
        cell.setFormulaValue(poiCell.getCellFormula());
        // ZSS-873
        if (isImportCache() && !poiCell.isCalcOnLoad() && !mustCalc(cell)) {
          ValueEval val = null;
          switch (poiCell.getCachedFormulaResultType()) {
            case Cell.CELL_TYPE_NUMERIC:
              val = new NumberEval(poiCell.getNumericCellValue());
              break;
            case Cell.CELL_TYPE_STRING:
              RichTextString poiRichTextString0 = poiCell.getRichStringCellValue();
              if (poiRichTextString0 != null && poiRichTextString0.numFormattingRuns() > 0) {
                SRichText richText = new RichTextImpl();
                importRichText(poiCell, poiRichTextString0, richText);
                val = new StringEval(richText.getText());
              } else {
                val = new StringEval(poiCell.getStringCellValue());
              }
              break;
            case Cell.CELL_TYPE_BOOLEAN:
              val = BoolEval.valueOf(poiCell.getBooleanCellValue());
              break;
            case Cell.CELL_TYPE_ERROR:
              val = ErrorEval.valueOf(poiCell.getErrorCellValue());
              break;
            case Cell.CELL_TYPE_BLANK:
            default:
              // do nothing
          }
          if (val != null) {
            ((AbstractCellAdv) cell).setFormulaResultValue(val);
          }
        }
        break;
      case Cell.CELL_TYPE_ERROR:
        cell.setErrorValue(PoiEnumConversion.toErrorCode(poiCell.getErrorCellValue()));
        break;
      case Cell.CELL_TYPE_BLANK:
        // do nothing because spreadsheet model auto creates blank cells
      default:
        // TODO log: leave an unknown cell type as a blank cell.
        break;
    }

    Hyperlink poiHyperlink = poiCell.getHyperlink();
    if (poiHyperlink != null) {
      String addr = poiHyperlink.getAddress();
      String label = poiHyperlink.getLabel();
      SHyperlink hyperlink =
          cell.setupHyperlink(
              PoiEnumConversion.toHyperlinkType(poiHyperlink.getType()),
              addr == null ? "" : addr,
              label == null ? "" : label);
      cell.setHyperlink(hyperlink);
    }

    Comment poiComment = poiCell.getCellComment();
    if (poiComment != null) {
      SComment comment = cell.setupComment();
      comment.setAuthor(poiComment.getAuthor());
      comment.setVisible(poiComment.isVisible());
      RichTextString poiRichTextString = poiComment.getString();
      if (poiRichTextString != null && poiRichTextString.numFormattingRuns() > 0) {
        importRichText(poiCell, poiComment.getString(), comment.setupRichText());
      } else {
        comment.setText(poiComment.toString());
      }
    }

    return cell;
  }