Example usage for org.apache.poi.xwpf.usermodel XWPFTableCell removeParagraph

List of usage examples for org.apache.poi.xwpf.usermodel XWPFTableCell removeParagraph

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFTableCell removeParagraph.

Prototype

public void removeParagraph(int pos) 

Source Link

Document

removes a paragraph of this tablecell

Usage

From source file:com.bxf.hradmin.testgen.service.impl.DocxTestGenerator.java

License:Open Source License

private void writeQuestion(QuestionSnapshot question, XWPFTableRow row) {
    //  & //ww  w .  j  ava 2s  .  c o m
    StringBuilder builder = new StringBuilder().append(question.getDesc());
    builder.append(NEW_LINE);
    question.getAnswers().forEach(answer -> builder.append(NEW_LINE).append(answer.getAnswerNo()).append(". ")
            .append(answer.getDesc()));
    String desc = builder.toString();
    XWPFTableCell cell = row.getCell(1);
    cell.removeParagraph(0);

    String[] lines = desc.split(NEW_LINE);
    for (String line : lines) {
        // add new line and insert new text
        XWPFParagraph paragraph = cell.addParagraph();
        //  & ??
        paragraph.setAlignment(ParagraphAlignment.BOTH);
        adjustLineHeight(paragraph);
        XWPFRun run = createRun(paragraph);
        run.setText(line);
    }
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>/*from   w  ww  .java2  s  . c o m*/
 * Helper method to clone {@link XWPFTableCell}.
 * </p>
 * 
 * @param in
 * @param out
 * @param converter
 */
public static void copy(XWPFTableCell in, XWPFTableCell out, UnaryOperator<String> converter) {
    // copy context
    CTTc outCTTc = out.getCTTc();
    CTTcPr outPR = outCTTc.isSetTcPr() ? outCTTc.getTcPr() : outCTTc.addNewTcPr();
    outPR.set(in.getCTTc().getTcPr());

    // clear all elements from out cell
    for (int i = out.getParagraphs().size() - 1; 0 <= i; i--) {
        out.removeParagraph(i);
    }

    // copy children
    for (XWPFParagraph inPara : in.getParagraphs()) {
        copy(inPara, out.addParagraph(), converter);
    }
}

From source file:org.ohdsi.rabbitInAHat.ETLDocumentGenerator.java

License:Apache License

private static void createCellParagraph(XWPFTableCell cell, String text) {
    if (text.equals("")) {
        return;//  ww w .  j a va 2  s .  co m
    }
    cell.removeParagraph(0);
    for (String line : text.split("\n")) {
        addToParagraph(cell.addParagraph(), line);
    }
}