List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph setBorderLeft
public void setBorderLeft(Borders border)
From source file:ch.admin.searchreplace.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);// ww w .j a v a 2 s .com 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(); }
From source file:com.crimelab.service.GalleryServiceImpl.java
@Override public XWPFDocument create(GalleryResults galleryResults, HttpSession session) { XWPFDocument document = null;// w w w .jav a 2s .c o m //Insert into database galleryDAO.insertResults(galleryResults); try { //Retrieving Template InputStream inpDocx = session.getServletContext() .getResourceAsStream("/WEB-INF/templates/CompositeSketch.docx"); document = new XWPFDocument(inpDocx); //Adding the picture XWPFParagraph pictureHolder = document.createParagraph(); XWPFRun pictureRun = pictureHolder.createRun(); FileInputStream getPhoto = new FileInputStream(galleryResults.getPhotoLocation()); FileInputStream getImage = new FileInputStream(galleryResults.getPhotoLocation()); ImageInputStream imageInput = ImageIO.createImageInputStream(getPhoto); BufferedImage bi = ImageIO.read(imageInput); int width = bi.getWidth() - 100; int height = bi.getHeight() - 100; pictureRun.addBreak(); pictureRun.addPicture(getImage, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(width), Units.toEMU(height)); pictureHolder.setBorderBottom(Borders.BASIC_BLACK_DASHES); pictureHolder.setBorderTop(Borders.BASIC_BLACK_DASHES); pictureHolder.setBorderLeft(Borders.BASIC_BLACK_DASHES); pictureHolder.setBorderRight(Borders.BASIC_BLACK_DASHES); pictureHolder.setAlignment(ParagraphAlignment.CENTER); // pictureRowHolder.getCell(0).setText("IMAGE PLACER"); //Case number and Date XWPFParagraph info = document.createParagraph(); XWPFRun caseNoAndDate = info.createRun(); caseNoAndDate.setText("Case Number: " + galleryResults.getCaseNo()); caseNoAndDate.addTab(); caseNoAndDate.addTab(); caseNoAndDate.addTab(); caseNoAndDate.addTab(); caseNoAndDate.setText(galleryResults.getDate()); caseNoAndDate.setFontSize(16); //Sketch Details XWPFParagraph caseDetails = document.createParagraph(); XWPFRun detailsParagraph = caseDetails.createRun(); detailsParagraph.setText("Offense/Incident: " + galleryResults.getOffenseIncident()); detailsParagraph.addBreak(); detailsParagraph.setText("Name/AKA: " + galleryResults.getNameAKA()); detailsParagraph.addBreak(); detailsParagraph.setText("Sex: " + galleryResults.getSex()); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.setText("Age: " + galleryResults.getAge()); detailsParagraph.addBreak(); detailsParagraph.setText("Height: " + galleryResults.getHeight()); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.setText("Weight: " + galleryResults.getWeight()); detailsParagraph.addBreak(); detailsParagraph.setText("Built: " + galleryResults.getBuilt()); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.addTab(); detailsParagraph.setText("Complexion: " + galleryResults.getComplexion()); detailsParagraph.addBreak(); detailsParagraph.setText("Other Information: " + galleryResults.getOtherInfo()); detailsParagraph.addBreak(); detailsParagraph.setText("Described by: " + galleryResults.getDescribedBy()); detailsParagraph.addBreak(); detailsParagraph.setText("Requesting party: " + galleryResults.getRequestingParty()); //Details Borders caseDetails.setBorderBottom(Borders.BASIC_BLACK_DASHES); caseDetails.setBorderTop(Borders.BASIC_BLACK_DASHES); caseDetails.setBorderLeft(Borders.BASIC_BLACK_DASHES); caseDetails.setBorderRight(Borders.BASIC_BLACK_DASHES); caseDetails.setAlignment(ParagraphAlignment.LEFT); //Reference Paragraph XWPFParagraph outsideDetails = document.createParagraph(); XWPFRun outsideDetailsRun = outsideDetails.createRun(); outsideDetailsRun.addBreak(); outsideDetailsRun.setText("Note: For reference"); outsideDetailsRun.addBreak(); outsideDetailsRun.setText("The witness indicates that this image is: " + galleryResults.getRating()); getPhoto.close(); getImage.close(); imageInput.close(); document.getXWPFDocument(); } catch (IOException | InvalidFormatException e) { e.printStackTrace(); } return document; }
From source file:com.dexter.fms.mbean.ReportsMBean.java
public void createWord(int type, String filename) { try {//from w ww .j a v a 2s .c om FacesContext context = FacesContext.getCurrentInstance(); XWPFDocument document = new XWPFDocument(); XWPFParagraph paragraphOne = document.createParagraph(); paragraphOne.setAlignment(ParagraphAlignment.CENTER); paragraphOne.setBorderBottom(Borders.SINGLE); paragraphOne.setBorderTop(Borders.SINGLE); paragraphOne.setBorderRight(Borders.SINGLE); paragraphOne.setBorderLeft(Borders.SINGLE); paragraphOne.setBorderBetween(Borders.SINGLE); XWPFRun paragraphOneRunOne = paragraphOne.createRun(); paragraphOneRunOne.setBold(true); paragraphOneRunOne.setItalic(true); paragraphOneRunOne.setText(getReport_title()); paragraphOneRunOne.addBreak(); exportWordTable(type, document); ByteArrayOutputStream baos = new ByteArrayOutputStream(); document.write(baos); String fileName = filename + ".docx"; writeFileToResponse(context.getExternalContext(), baos, fileName, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); context.responseComplete(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.ecm.poi.SimpleDocument.java
License:Apache License
@Test public void xwpfTest() throws Exception { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setBorderBottom(Borders.DOUBLE);/*from w w w . j a 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("d:\\temp\\simple.docx"); doc.write(out); out.close(); }
From source file:com.foc.vaadin.gui.layouts.validationLayout.FVValidationLayout.java
License:Apache License
public static void fillWordDocument(XWPFDocument doc) { try {//ww w . j a v a2s .c o m 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.BOTH); p3.setSpacingLineRule(LineSpacingRule.EXACT); p3.setIndentationFirstLine(600); XWPFRun r4 = p3.createRun(); r4.setTextPosition(200); 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" + "......."); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.gezipu360.cashier.bean.word.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 .j a v a 2 s .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.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(); }
From source file:com.glodon.tika.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);/* ww w. ja v a 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.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(); doc.close(); }
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 ? ?//w w w . ja v a2s . c o m 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:edu.cqupt.test.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);/*from w w w . ja v a2 s . 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.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("??? " + "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("F://simple.docx"); doc.write(out); out.close(); }
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);//from www . jav a2s. 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.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(); }