List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph getCTP
@Internal
public CTP getCTP()
From source file:genrate_doc.java
void changeOrientation(XWPFDocument document, String orientation) { CTDocument1 doc = document.getDocument(); CTBody body = doc.getBody();// w w w . jav a 2 s. c om CTSectPr section = body.addNewSectPr(); XWPFParagraph para = document.createParagraph(); CTP ctp = para.getCTP(); CTPPr br = ctp.addNewPPr(); br.setSectPr(section); CTPageSz pageSize; if (section.isSetPgSz()) { pageSize = section.getPgSz(); } else { pageSize = section.addNewPgSz(); } if (orientation.equals("landscape")) { pageSize.setOrient(STPageOrientation.LANDSCAPE); pageSize.setW(BigInteger.valueOf(842 * 20)); pageSize.setH(BigInteger.valueOf(595 * 20)); } else { pageSize.setOrient(STPageOrientation.PORTRAIT); pageSize.setH(BigInteger.valueOf(842 * 20)); pageSize.setW(BigInteger.valueOf(595 * 20)); } }
From source file:apachepoitest.DocumentPropertyChecker.java
public static Boolean checkIfParagraphHasProperty(XWPFParagraph p, String property, String value) { try {/* www.ja v a 2 s . co m*/ switch (property) { case "LINE SPACING": XWPFParagraphClone pc; pc = new XWPFParagraphClone(p.getCTP(), p.getBody()); return pc.getCTSpacing(false).getLine().floatValue() / 240 == Float.parseFloat(value); case "NUMBERING FORMAT": return p.getNumFmt().equalsIgnoreCase(value); case "ALIGN": return p.getAlignment().toString().equalsIgnoreCase(value); default: System.out.println("Property " + property + " does not exist!"); return false; } } catch (NullPointerException e) { return false; } }
From source file:apachepoitest.DocumentPropertyEnumerator.java
public static void showParagraphPropertiesOnly(List<XWPFParagraph> lp) { int i1 = 1;/* w ww. j a v a 2 s . c o m*/ for (XWPFParagraph p : lp) { //System.out.println(p.getStyleID() + " " + sl1.getStyle(p.getStyleID()).getCTStyle().xmlText()); System.out.println("____________________________________"); if (p.getParagraphText().trim().length() > 0) { System.out.println("\n#" + i1++ + " LINE: " + p.getParagraphText()); System.out.println("ALIGNMENT: " + p.getAlignment().toString()); //Uncomment to display other properties System.out.println("BORDER BETWEEN: " + p.getBorderBetween().toString()); System.out.println("BORDER BOTTOM: " + p.getBorderBottom().toString()); System.out.println("BORDER LEFT: " + p.getBorderLeft().toString()); System.out.println("BORDER RIGHT: " + p.getBorderRight().toString()); System.out.println("BORDER TOP: " + p.getBorderTop().toString()); System.out.println("BODY ELEMENT TYPE: " + p.getElementType().toString()); System.out.println("FOOTNOTE: " + p.getFootnoteText()); System.out.println("INDENTATION 1ST LINE: " + p.getIndentationFirstLine()); System.out.println("INDENTATION HANGING: " + p.getIndentationHanging()); System.out.println("INDENTATION LEFT: " + p.getIndentationLeft()); System.out.println("INDENTATION RIGHT: " + p.getIndentationRight()); System.out.println("NUMBERING FORMAT: " + p.getNumFmt()); System.out.println("NUMERIC STYLE ILVL: " + p.getNumIlvl()); System.out.println("STYLE: " + p.getBody().getXWPFDocument().getStyles().getStyle(p.getStyleID())); XWPFParagraphClone pc; pc = new XWPFParagraphClone(p.getCTP(), p.getBody()); System.out.println("SPACING VALUE: " + pc.getCTSpacing(false).getLine().floatValue() / 240); System.out.println("SPACING AFTER: " + p.getSpacingAfter()); System.out.println("SPACING AFTER LINES: " + p.getSpacingAfterLines()); System.out.println("SPACING BEFORE: " + p.getSpacingBefore()); System.out.println("SPACING BEFORE LINES: " + p.getSpacingBeforeLines()); System.out.println("SPACING LINE RULE: " + p.getSpacingLineRule()); System.out.println("VERTICAL ALIGNMENT: " + p.getVerticalAlignment()); } // can also use .searchText to look for a string else { // Uncomment to display lines //System.out.println("\n#" + i1++ + " LINE: <SPACE>"); } } }
From source file:com.bxf.hradmin.testgen.service.impl.DocxTestGenerator.java
License:Open Source License
private void adjustLineHeight(XWPFParagraph paragraph) { // ??/*from w w w . ja v a2s. co m*/ paragraph.setSpacingAfter(0); paragraph.setSpacingBefore(0); // ? CTSpacing spacing = paragraph.getCTP().getPPr().getSpacing(); spacing.setLineRule(STLineSpacingRule.EXACT); spacing.setLine(BigInteger.valueOf(360)); }
From source file:com.min.word.core.MakeWordFileTest.java
License:Apache License
public static void main(String[] args) throws Exception { String fileName = "test.docx"; System.out.println("---------- Word Create Start ------------"); // word ? ?/* ww w . ja v a2s. c om*/ XWPFDocument document = new XWPFDocument(); FileOutputStream out = new FileOutputStream(new File(fileName)); System.out.println("---------- Create Blank Success ------------"); //Paragraph ? XWPFParagraph paragraph = document.createParagraph(); System.out.println("---------- Create Paragraph Success ------------"); //border ? paragraph.setBorderBottom(Borders.BASIC_BLACK_DASHES); paragraph.setBorderLeft(Borders.BASIC_BLACK_DASHES); paragraph.setBorderRight(Borders.BASIC_BLACK_DASHES); paragraph.setBorderTop(Borders.BASIC_BLACK_DASHES); System.out.println("---------- Create Border Success ------------"); XWPFRun run = paragraph.createRun(); run.setText("At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming Languages."); System.out.println("---------- Text Write to File ------------"); //Table ? XWPFTable table = document.createTable(); //row XWPFTableRow rowOne = table.getRow(0); rowOne.getCell(0).setText("Col One, Row One"); rowOne.addNewTableCell().setText("Col Tow, Row One"); rowOne.addNewTableCell().setText("Col Three, Row One"); //row XWPFTableRow rowTow = table.createRow(); rowTow.getCell(0).setText("Col One, Row Tow"); rowTow.getCell(1).setText("Col Tow, Row Tow"); rowTow.getCell(2).setText("Col Three, Row Tow"); //row XWPFTableRow rowThree = table.createRow(); rowThree.getCell(0).setText("Col One, Row Three"); rowThree.getCell(1).setText("Col Tow, Row Three"); rowThree.getCell(2).setText("Col Three, Row Three"); System.out.println("---------- Create Table Success ------------"); //Add Image XWPFParagraph imageParagraph = document.createParagraph(); XWPFRun imageRun = imageParagraph.createRun(); imageRun.addPicture(new FileInputStream("test.png"), XWPFDocument.PICTURE_TYPE_PNG, "test.png", Units.toEMU(300), Units.toEMU(300)); System.out.println("---------- Create Image Success ------------"); //Hyperlink XWPFParagraph hyperlink = document.createParagraph(); String id = hyperlink.getDocument().getPackagePart() .addExternalRelationship("http://niee.kr", XWPFRelation.HYPERLINK.getRelation()).getId(); CTR ctr = CTR.Factory.newInstance(); CTHyperlink ctHyperlink = hyperlink.getCTP().addNewHyperlink(); ctHyperlink.setId(id); CTText ctText = CTText.Factory.newInstance(); ctText.setStringValue("Hyper-Link TEST"); ctr.setTArray(new CTText[] { ctText }); // ???? ? CTColor color = CTColor.Factory.newInstance(); color.setVal("0000FF"); CTRPr ctrPr = ctr.addNewRPr(); ctrPr.setColor(color); ctrPr.addNewU().setVal(STUnderline.SINGLE); // CTFonts fonts = ctrPr.isSetRFonts() ? ctrPr.getRFonts() : ctrPr.addNewRFonts(); fonts.setAscii("?? "); fonts.setEastAsia("?? "); fonts.setHAnsi("?? "); // ? CTHpsMeasure sz = ctrPr.isSetSz() ? ctrPr.getSz() : ctrPr.addNewSz(); sz.setVal(new BigInteger("24")); ctHyperlink.setRArray(new CTR[] { ctr }); hyperlink.setAlignment(ParagraphAlignment.LEFT); hyperlink.setVerticalAlignment(TextAlignment.CENTER); System.out.println("---------- Create Hyperlink Success ------------"); //Font style XWPFParagraph fontStyle = document.createParagraph(); //set Bold an Italic XWPFRun boldAnItalic = fontStyle.createRun(); boldAnItalic.setBold(true); boldAnItalic.setItalic(true); boldAnItalic.setText("Bold an Italic"); boldAnItalic.addBreak(); //set Text Position XWPFRun textPosition = fontStyle.createRun(); textPosition.setText("Set Text Position"); textPosition.setTextPosition(100); //Set Strike through and font Size and Subscript XWPFRun otherStyle = fontStyle.createRun(); otherStyle.setStrike(true); otherStyle.setFontSize(20); otherStyle.setSubscript(VerticalAlign.SUBSCRIPT); otherStyle.setText(" Set Strike through and font Size and Subscript"); System.out.println("---------- Set Font Style ------------"); //Set Alignment Paragraph XWPFParagraph alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.RIGHT); XWPFRun alignRight = alignment.createRun(); alignRight.setText( "At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming " + "Languages."); //Alignment to Center alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.CENTER); XWPFRun alignCenter = alignment.createRun(); alignCenter.setText("The endeavour started by Mohtashim, an AMU " + "alumni, who is the founder and the managing director " + "of Tutorials Point (I) Pvt. Ltd. He came up with the " + "website tutorialspoint.com in year 2006 with the help" + "of handpicked freelancers, with an array of tutorials" + " for computer programming languages. "); System.out.println("---------- Set Alignment ------------"); //word ? document.write(out); out.close(); System.out.println("---------- Save File Name : " + fileName + " ------------"); System.out.println("---------- Word Create End ------------"); }
From source file:com.project3.utils.poiold.DocumentPropertyEnumerator.java
public static void showAllParagraphProperties(List<XWPFParagraph> lp) { int i1 = 1;// w w w.j a va2s . com for (XWPFParagraph p : lp) { //System.out.println(p.getStyleID() + " " + sl1.getStyle(p.getStyleID()).getCTStyle().xmlText()); System.out.println("____________________________________"); if (p.getParagraphText().trim().length() > 0) { System.out.println("\n#" + i1++ + " LINE: " + p.getParagraphText()); System.out.println("ALIGNMENT: " + p.getAlignment().toString()); System.out.println("BORDER BETWEEN: " + p.getBorderBetween().toString()); System.out.println("BORDER BOTTOM: " + p.getBorderBottom().toString()); System.out.println("BORDER LEFT: " + p.getBorderLeft().toString()); System.out.println("BORDER RIGHT: " + p.getBorderRight().toString()); System.out.println("BORDER TOP: " + p.getBorderTop().toString()); System.out.println("BODY ELEMENT TYPE: " + p.getElementType().toString()); System.out.println("FOOTNOTE: " + p.getFootnoteText()); System.out.println("INDENTATION 1ST LINE: " + p.getIndentationFirstLine()); System.out.println("INDENTATION HANGING: " + p.getIndentationHanging()); System.out.println("INDENTATION LEFT: " + p.getIndentationLeft()); System.out.println("INDENTATION RIGHT: " + p.getIndentationRight()); System.out.println("NUMBERING FORMAT: " + p.getNumFmt()); System.out.println("NUMERIC STYLE ILVL: " + p.getNumIlvl()); System.out.println("STYLE: " + p.getBody().getXWPFDocument().getStyles().getStyle(p.getStyleID())); XWPFParagraphClone pc; pc = new XWPFParagraphClone(p.getCTP(), p.getBody()); System.out.println("SPACING VALUE: " + pc.getCTSpacing(false).getLine().floatValue() / 240); System.out.println("SPACING AFTER: " + p.getSpacingAfter()); System.out.println("SPACING AFTER LINES: " + p.getSpacingAfterLines()); System.out.println("SPACING BEFORE: " + p.getSpacingBefore()); System.out.println("SPACING BEFORE LINES: " + p.getSpacingBeforeLines()); System.out.println("SPACING LINE RULE: " + p.getSpacingLineRule()); System.out.println("VERTICAL ALIGNMENT: " + p.getVerticalAlignment()); } // can also use .searchText to look for a string else { // Uncomment to display lines //System.out.println("\n#" + i1++ + " LINE: <SPACE>"); } } }
From source file:de.knowwe.include.export.CodeExporter.java
License:Open Source License
@Override public void export(Section<Type> section, DocumentBuilder manager) throws ExportException { // preformatted code: make each line a paragraph String text = Strings.trim(section.getText()).replaceAll(prefix, "").replaceAll(postfix, ""); String[] lines = Strings.trimBlankLinesAndTrailingLineBreak(text).split("\n\r?"); for (String line : lines) { XWPFParagraph paragraph = manager.getNewParagraph(DocumentBuilder.Style.code); CTR ctr = paragraph.getCTP().addNewR(); ctr.addNewRPr();//from w ww . j a va 2 s .c o m ctr.addNewT().setStringValue(line + "\n\r"); manager.closeParagraph(); } }
From source file:de.knowwe.include.export.DefinitionExporter.java
License:Open Source License
@Override public void export(Section<DefinitionType> section, DocumentBuilder manager) throws ExportException { XWPFDocument document = manager.getDocument(); BigInteger abstractID = ListExporter.getAbstractIdUnordered(document); BigInteger numID = document.getNumbering().addNum(abstractID); XWPFParagraph paragraph = manager.getNewParagraph(Style.list); paragraph.setNumID(numID);/*from w w w. j a v a 2 s .c o m*/ paragraph.getCTP().getPPr().getNumPr().addNewIlvl().setVal(BigInteger.valueOf(0)); ListBuilder listBuilder = new ListBuilder(manager); listBuilder.setBold(true); listBuilder.export(section.get().getHeadSection(section)); listBuilder.setBold(false); manager.append(": "); manager.getParagraph().createRun().addCarriageReturn(); listBuilder.export(section.get().getDataSection(section)); manager.closeParagraph(); }
From source file:de.knowwe.include.export.HeaderExporter.java
License:Open Source License
public static XWPFRun createCrossReferenceRun(String refID, DocumentBuilder builder) { XWPFParagraph paragraph = builder.getParagraph(); if (refID == null) { return paragraph.createRun(); } else {/* w w w. j a va 2 s .co m*/ HeaderExporter self = builder.getModel().getExporter(HeaderExporter.class); BigInteger id = BigInteger.valueOf(self.bookmarkIndex++); CTP ctp = paragraph.getCTP(); CTBookmark start = ctp.addNewBookmarkStart(); start.setId(id); start.setName(refID); XWPFRun run = paragraph.createRun(); CTMarkupRange end = ctp.addNewBookmarkEnd(); end.setId(id); return run; } }
From source file:de.knowwe.include.export.LinkExporter.java
License:Open Source License
@Override public void export(Section<LinkType> section, DocumentBuilder builder) throws ExportException { ExportUtils.addRequiredSpace(builder); Section<?> target = canExportAsReference(builder.getModel().getManager(), section); if (target != null) { String refID = HeaderExporter.getCrossReferenceID(target); // Variant 1: // Export as hyperlinks to anchor // --> Text of link is defined as by wiki user XWPFParagraph paragraph = builder.getParagraph(); CTP ctp = paragraph.getCTP(); CTHyperlink hyperlink = ctp.addNewHyperlink(); hyperlink.setAnchor(refID);//from ww w. j a va 2 s .c om XWPFHyperlinkRun run = new XWPFHyperlinkRun(hyperlink, hyperlink.addNewR(), paragraph); run.setText(LinkType.getDisplayText(section)); // Variant 2: // Export as word-field (REF ... \h) // --> More word-like, // but reference text is always updated to the header title // CTP p = builder.getParagraph().getCTP(); // p.addNewPPr(); // CTR run = p.addNewR(); // run.addNewRPr().addNewNoProof(); // run.addNewFldChar().setFldCharType(STFldCharType.BEGIN); // // pageref run // run = p.addNewR(); // run.addNewRPr().addNewNoProof(); // CTText text = run.addNewInstrText(); // text.setSpace(Space.PRESERVE); // // bookmark reference // text.setStringValue(" REF " + refID + " \\h "); // p.addNewR().addNewRPr().addNewNoProof(); // run = p.addNewR(); // run.addNewRPr().addNewNoProof(); // run.addNewFldChar().setFldCharType(STFldCharType.SEPARATE); // // page number run // run = p.addNewR(); // run.addNewRPr().addNewNoProof(); // run.addNewT().setStringValue(LinkType.getDisplayText(section)); // run = p.addNewR(); // run.addNewRPr().addNewNoProof(); // run.addNewFldChar().setFldCharType(STFldCharType.END); } else { builder.append(LinkType.getDisplayText(section)); } }