Exemplo n.º 1
0
  /** Test setting the text, then adding multiple paragraphs and retrieve text */
  public void testSetAddMultipleParagraphs() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();
    XSSFDrawing drawing = sheet.createDrawingPatriarch();

    XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));

    shape.setText("Line 1");

    XSSFTextParagraph para = shape.addNewTextParagraph();
    para.addNewTextRun().setText("Line 2");

    para = shape.addNewTextParagraph();
    para.addNewTextRun().setText("Line 3");

    List<XSSFTextParagraph> paras = shape.getTextParagraphs();
    assertEquals(
        3,
        paras
            .size()); // this should be 3 as we overwrote the default paragraph with setText, then
                      // added 2 new paragraphs
    assertEquals("Line 1\nLine 2\nLine 3", shape.getText());

    assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
  }
Exemplo n.º 2
0
  /** Test addNewTextParagraph */
  public void testAddNewTextParagraph() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();
    XSSFDrawing drawing = sheet.createDrawingPatriarch();

    XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));

    XSSFTextParagraph para = shape.addNewTextParagraph();
    para.addNewTextRun().setText("Line 1");

    List<XSSFTextParagraph> paras = shape.getTextParagraphs();
    assertEquals(
        2,
        paras
            .size()); // this should be 2 as XSSFSimpleShape creates a default paragraph (no text),
                      // and then we add a string to that.

    List<XSSFTextRun> runs = para.getTextRuns();
    assertEquals(1, runs.size());
    assertEquals("Line 1", runs.get(0).getText());

    assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
  }