Example usage for org.apache.poi.xwpf.usermodel ParagraphAlignment RIGHT

List of usage examples for org.apache.poi.xwpf.usermodel ParagraphAlignment RIGHT

Introduction

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

Prototype

ParagraphAlignment RIGHT

To view the source code for org.apache.poi.xwpf.usermodel ParagraphAlignment RIGHT.

Click Source Link

Usage

From source file:File.DOCX.WriteDocx.java

public void Write(String header, String footer, String kalimat, String alignment, String path) {
    try {/*from w ww  . j  a v a2  s .c om*/

        CreateHeader(header);
        CreateFooter(footer);
        ParagraphAlignment align = null;
        if (alignment.equalsIgnoreCase("left")) {
            align = ParagraphAlignment.LEFT;
        } else if (alignment.equalsIgnoreCase("right")) {
            align = ParagraphAlignment.RIGHT;
        } else if (alignment.equalsIgnoreCase("center")) {
            align = ParagraphAlignment.CENTER;
        }
        //write body content
        String[] split_kalimat = kalimat.split("\n");
        for (String text : split_kalimat) {
            XWPFParagraph bodyParagraph = docx.createParagraph();
            bodyParagraph.setAlignment(align);
            XWPFRun r = bodyParagraph.createRun();
            r.setText(text);
        }

        FileOutputStream out = new FileOutputStream(path);
        docx.write(out);
        out.close();
        System.out.println("Done");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsC(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNull(jc);//  ww w  . jav a 2  s.  c  o m

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    Assert.assertEquals(ParagraphAlignment.RIGHT, alignment);
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsF(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNotNull(jc);//from  w  w  w  .j a va2 s.c o m
    Assert.assertEquals(jc.intValue(), STVerticalJc.INT_CENTER);

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    Assert.assertEquals(ParagraphAlignment.RIGHT, alignment);
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsI(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNotNull(jc);//from  w w w  .  j  a v  a  2 s  . c om
    Assert.assertEquals(jc.intValue(), STVerticalJc.INT_BOTTOM);

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    Assert.assertEquals(ParagraphAlignment.RIGHT, alignment);
}

From source file:org.articleEditor.insertContent.DocumentUpdater1.java

License:Apache License

private ParagraphAlignment documentToPOI(int alignment) {
    switch (alignment) {
    case ALIGN_LEFT:
        return ParagraphAlignment.LEFT;
    case ALIGN_RIGHT:
        return ParagraphAlignment.RIGHT;
    case ALIGN_CENTER:
        return ParagraphAlignment.CENTER;
    case ALIGN_JUSTIFIED:
        return ParagraphAlignment.DISTRIBUTE;
    }/* w ww  .ja v a  2  s  .  com*/
    return ParagraphAlignment.LEFT;
}

From source file:org.articleEditor.insertContent.POIDocxReader.java

License:Apache License

protected void processParagraph(XWPFParagraph paragraph) throws BadLocationException {
    parAttrs = new SimpleAttributeSet();
    ParagraphAlignment alignment = paragraph.getAlignment();
    if (alignment == ParagraphAlignment.CENTER) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_CENTER);
    } else if (alignment == ParagraphAlignment.LEFT) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_LEFT);
    } else if (alignment == ParagraphAlignment.RIGHT) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_RIGHT);
    } else if (alignment == ParagraphAlignment.BOTH || alignment == ParagraphAlignment.DISTRIBUTE) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_JUSTIFIED);
    }/* ww w  . j  a  v a2s . co m*/
    List<TabStop> tabs = new ArrayList<>();
    int leftIndentation = paragraph.getIndentationLeft();
    if (leftIndentation > 0) {
        float indentation = leftIndentation / INDENTS_MULTIPLIER;
        StyleConstants.setLeftIndent(parAttrs, indentation);
        /*TabStop stop = new TabStop(pos, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
         tabs.add(stop);*/
    }
    int rightIndentation = paragraph.getIndentationRight();
    if (rightIndentation > 0) {
        float indentation = rightIndentation / INDENTS_MULTIPLIER;
        StyleConstants.setLeftIndent(parAttrs, indentation);
        /*TabStop stop = new TabStop(pos, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
         tabs.add(stop);*/
    }
    /*TabSet tabSet = new TabSet(tabs.toArray(new TabStop[tabs.size()]));
     StyleConstants.setTabSet(parAttrs, tabSet);*/
    int firstLineIndentation = paragraph.getIndentationFirstLine();
    if (firstLineIndentation > 0) {
        float indentation = firstLineIndentation / INDENTS_MULTIPLIER;
        StyleConstants.setFirstLineIndent(parAttrs, indentation);
        /*TabStop stop = new TabStop(pos, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
         tabs.add(stop);*/
    }

    int spacingBefore = paragraph.getSpacingBefore();
    if (spacingBefore > 0) {
        int before = spacingBefore / INDENTS_MULTIPLIER;
        StyleConstants.setSpaceAbove(parAttrs, before);
    }
    int spacingAfter = paragraph.getSpacingAfter();
    if (spacingAfter > 0) {
        int after = spacingAfter / INDENTS_MULTIPLIER;
        StyleConstants.setSpaceAbove(parAttrs, after);
    }
    LineSpacingRule spacingLine = paragraph.getSpacingLineRule();
    if (spacingLine == LineSpacingRule.AT_LEAST || spacingLine == LineSpacingRule.AUTO) {
        float spacing = spacingLine.getValue() / 240;
        StyleConstants.setLineSpacing(parAttrs, spacing);
    }
    document.setParagraphAttributes(currentOffset, 1, parAttrs, true);
    for (XWPFRun run : paragraph.getRuns()) {
        processRun(run);
    }
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

/**
 * Header title/*from  w w w. j a v a2 s  .c om*/
 * 
 * @param document
 * @param text
 * @throws IOException
 */
public void pageHeader(XWPFDocument document, String text) throws IOException {
    CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
    XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
    CTP ctpHeader = CTP.Factory.newInstance();
    CTR ctrHeader = ctpHeader.addNewR();
    CTText ctHeader = ctrHeader.addNewT();
    ctHeader.setStringValue(text);
    XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, document);
    headerParagraph.setAlignment(ParagraphAlignment.RIGHT);
    XWPFParagraph[] parsHeader = new XWPFParagraph[1];
    parsHeader[0] = headerParagraph;
    policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader);
}

From source file:org.robert.study.service.merge.doc.SimpleDocument.java

License:Apache License

public static void main(String[] args) throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);//  w w w .  ja  va2 s . c om
    p1.setBorderTop(Borders.DOUBLE);

    p1.setBorderRight(Borders.DOUBLE);
    p1.setBorderLeft(Borders.DOUBLE);
    p1.setBorderBetween(Borders.SINGLE);

    p1.setVerticalAlignment(TextAlignment.TOP);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setBold(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.RIGHT);

    // BORDERS
    p2.setBorderBottom(Borders.DOUBLE);
    p2.setBorderTop(Borders.DOUBLE);
    p2.setBorderRight(Borders.DOUBLE);
    p2.setBorderLeft(Borders.DOUBLE);
    p2.setBorderBetween(Borders.SINGLE);

    XWPFRun r2 = p2.createRun();
    r2.setText("jumped over the lazy dog");
    r2.setStrike(true);
    r2.setFontSize(20);

    XWPFRun r3 = p2.createRun();
    r3.setText("and went away");
    r3.setStrike(true);
    r3.setFontSize(20);
    r3.setSubscript(VerticalAlign.SUPERSCRIPT);

    XWPFParagraph p3 = doc.createParagraph();
    p3.setWordWrap(true);
    p3.setPageBreak(true);

    // p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    p3.setSpacingLineRule(LineSpacingRule.EXACT);

    p3.setIndentationFirstLine(600);

    XWPFRun r4 = p3.createRun();
    r4.setTextPosition(20);
    r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
            + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, "
            + "And by opposing end them? To die: to sleep; ");
    r4.addBreak(BreakType.PAGE);
    r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
            + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
            + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
    r4.setItalic(true);
    // This would imply that this break shall be treated as a simple line
    // break, and break the line after that word:

    XWPFRun r5 = p3.createRun();
    r5.setTextPosition(-10);
    r5.setText("For in that sleep of death what dreams may come");
    r5.addCarriageReturn();
    r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
            + "That makes calamity of so long life;");
    r5.addBreak();
    r5.setText("For who would bear the whips and scorns of time,"
            + "The oppressor's wrong, the proud man's contumely,");

    r5.addBreak(BreakClear.ALL);
    r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
            + ".......");

    FileOutputStream out = new FileOutputStream("z://simple.docx");
    doc.write(out);
    out.close();

}

From source file:ParserDoc.SimpleDocument.java

License:Apache License

public static void main(String[] args) throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);/*  w w  w.  ja  va 2s.c  o  m*/
    p1.setBorderTop(Borders.DOUBLE);

    p1.setBorderRight(Borders.DOUBLE);
    p1.setBorderLeft(Borders.DOUBLE);
    p1.setBorderBetween(Borders.SINGLE);

    p1.setVerticalAlignment(TextAlignment.TOP);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setBold(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.RIGHT);

    //BORDERS
    p2.setBorderBottom(Borders.DOUBLE);
    p2.setBorderTop(Borders.DOUBLE);
    p2.setBorderRight(Borders.DOUBLE);
    p2.setBorderLeft(Borders.DOUBLE);
    p2.setBorderBetween(Borders.SINGLE);

    XWPFRun r2 = p2.createRun();
    r2.setText("jumped over the lazy dog");
    //  r2.setStrikeThrough(true);
    r2.setFontSize(20);

    XWPFRun r3 = p2.createRun();
    r3.setText("and went away");
    //  r3.setStrikeThrough(true);
    r3.setFontSize(20);
    r3.setSubscript(VerticalAlign.SUPERSCRIPT);

    XWPFParagraph p3 = doc.createParagraph();
    // p3.setWordWrapped(true);
    p3.setPageBreak(true);

    //p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    // p3.setSpacingBetween(15, LineSpacingRule.EXACT);

    p3.setIndentationFirstLine(600);

    XWPFRun r4 = p3.createRun();
    r4.setTextPosition(20);
    r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
            + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, "
            + "And by opposing end them? To die: to sleep; ");
    r4.addBreak(BreakType.PAGE);
    r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
            + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
            + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
    r4.setItalic(true);
    //This would imply that this break shall be treated as a simple line break, and break the line after that word:

    XWPFRun r5 = p3.createRun();
    r5.setTextPosition(-10);
    r5.setText("For in that sleep of death what dreams may come");
    r5.addCarriageReturn();
    r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
            + "That makes calamity of so long life;");
    r5.addBreak();
    r5.setText("For who would bear the whips and scorns of time,"
            + "The oppressor's wrong, the proud man's contumely,");

    r5.addBreak(BreakClear.ALL);
    r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
            + ".......");

    FileOutputStream out = new FileOutputStream("simple.docx");
    doc.write(out);
    out.close();
    // out.close ();
}

From source file:ro.dabuno.office.integration.SimpleDocument.java

License:Apache License

public static void main(String[] args) throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p0 = doc.createParagraph();
    XWPFRun r0 = p0.createRun();//from   w w  w.java 2s .  c  o m
    r0.setBold(false);
    r0.setText("Domnule");
    XWPFRun r00 = p0.createRun();
    r00.setBold(true);
    r00.setText(" Ionescu Ion");

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);
    p1.setBorderTop(Borders.DOUBLE);

    p1.setBorderRight(Borders.DOUBLE);
    p1.setBorderLeft(Borders.DOUBLE);
    p1.setBorderBetween(Borders.SINGLE);

    p1.setVerticalAlignment(TextAlignment.TOP);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setBold(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.RIGHT);

    //BORDERS
    p2.setBorderBottom(Borders.DOUBLE);
    p2.setBorderTop(Borders.DOUBLE);
    p2.setBorderRight(Borders.DOUBLE);
    p2.setBorderLeft(Borders.DOUBLE);
    p2.setBorderBetween(Borders.SINGLE);

    XWPFRun r2 = p2.createRun();
    r2.setText("jumped over the lazy dog");
    r2.setStrike(true);
    r2.setFontSize(20);

    XWPFRun r3 = p2.createRun();
    r3.setText("and went away");
    r3.setStrike(true);
    r3.setFontSize(20);
    r3.setSubscript(VerticalAlign.SUPERSCRIPT);

    XWPFParagraph p3 = doc.createParagraph();
    p3.setWordWrap(true);
    p3.setPageBreak(true);

    //p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    p3.setSpacingLineRule(LineSpacingRule.EXACT);

    p3.setIndentationFirstLine(600);

    XWPFRun r4 = p3.createRun();
    r4.setTextPosition(20);
    r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
            + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, "
            + "And by opposing end them? To die: to sleep; ");
    r4.addBreak(BreakType.PAGE);
    r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
            + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
            + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
    r4.setItalic(true);
    //This would imply that this break shall be treated as a simple line break, and break the line after that word:

    XWPFRun r5 = p3.createRun();
    r5.setTextPosition(-10);
    r5.setText("For in that sleep of death what dreams may come");
    r5.addCarriageReturn();
    r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
            + "That makes calamity of so long life;");
    r5.addBreak();
    r5.setText("For who would bear the whips and scorns of time,"
            + "The oppressor's wrong, the proud man's contumely,");

    r5.addBreak(BreakClear.ALL);
    r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
            + ".......");

    FileOutputStream out = new FileOutputStream("simple.docx");
    doc.write(out);
    out.close();

}