List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun setFontFamily
public void setFontFamily(String fontFamily)
From source file:library.Form_Library.java
private void btPrintReaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPrintReaderActionPerformed try {// w w w . j a va 2s .co m // TODO add your handling code here: FileOutputStream fos = new FileOutputStream(tfID.getText() + " - " + tfName.getText() + ".docx"); XWPFDocument doc = new XWPFDocument(); XWPFParagraph paraTit = doc.createParagraph(); paraTit.setAlignment(ParagraphAlignment.CENTER); XWPFRun paraTitRun = paraTit.createRun(); paraTitRun.setBold(true); paraTitRun.setText("Reader Information"); paraTitRun.setFontFamily("Times New Roman"); paraTitRun.setFontSize(20); String content = this.taPrintReader.getText(); XWPFRun paraTitRun2 = doc.createParagraph().createRun(); paraTitRun2.setFontFamily("Times New Roman"); paraTitRun2.setFontSize(16); if (content.contains("\n")) { String[] lines = content.split("\n"); paraTitRun2.setText(lines[0], 0); // set first line into XWPFRun for (int i = 1; i < lines.length; i++) { // add break and insert new text paraTitRun2.addBreak(); paraTitRun2.setText(lines[i]); } } else { paraTitRun2.setText(content, 0); } doc.write(fos); fos.close(); JOptionPane.showMessageDialog(null, "The document created successfully!!"); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex); } }
From source file:nl.detoren.ijc.io.OutputIntekenlijst.java
License:Open Source License
public boolean export(Groepen groepen) { try {/*from www .j av a 2 s. c o m*/ logger.log(Level.INFO, "Wedstrijden wegschrijven naar Excel"); FileInputStream file = new FileInputStream("Leeg.docx"); XWPFDocument document = new XWPFDocument(file); XWPFParagraph paragraph = document.getLastParagraph(); setDoubleLineSpacing(paragraph); XWPFRun run = paragraph.createRun(); run.setFontFamily("Courier New"); run.setFontSize(12); String result; result = "Intekenlijst aangemaakt met " + IJCController.c().appTitle + " voor " + IJCController.c().verenigingNaam; run.setText(result); run.addCarriageReturn(); // separate previous text from break for (int i = 0; i < groepen.getAantalGroepen(); ++i) { if (i >= 1) run.addBreak(); Groep groep = groepen.getGroepById(i); result = "Stand na " + groepen.getRonde() + "e ronde, " + groepen.getPeriode(); result += "e periode " + groep.getNaam() + " (" + groep.getSpelers().size() + ")\n"; run.setText(result); run.addBreak(); result = " Naam ini zw rating gespeeld tegen pnt\n"; run.setText(result); run.addBreak(); result = "-----------------------------------------------------------------------\n"; run.setText(result); run.addBreak(); for (Speler s : groep.getSpelers()) { result = s.toPrintableString(false); run.setText(result); run.addBreak(); } if (IJCController.c().exportDoorschuivers) { int ndoor = IJCController.c().bepaalAantalDoorschuiversVolgendeRonde(groep.getNiveau(), groepen.getPeriode(), groepen.getRonde()); if (i - 1 >= 0) { run.setText(IJCController.c().exportDoorschuiversStart + "\n"); run.addBreak(); Groep lager = groepen.getGroepById(i - 1); if (ndoor > 1) { for (int j = 0; j < ndoor; j++) { Speler s = lager.getSpelerByID(j + 1); run.setText(s.toPrintableString(false, true) + "\n"); run.addBreak(); } run.setText(IJCController.c().exportDoorschuiversStop + "\n" + "\n"); } else { // Bij n doorschuiver, alleen doorschuiven als // kampioen Speler s1 = lager.getSpelerByID(1); Speler s2 = lager.getSpelerByID(2); if ((s2 != null) && ((s1.getPunten() - s2.getPunten()) > 4)) { run.setText(s1.toPrintableString(false, true) + "\n"); run.addBreak(); } } } } run.addCarriageReturn(); // separate previous text from break run.addBreak(BreakType.PAGE); } // Close input file file.close(); // Store Excel to new file String dirName = "R" + groepen.getPeriode() + "-" + groepen.getRonde(); new File(dirName).mkdirs(); String filename = dirName + File.separator + "IntekenlijstR" + groepen.getPeriode() + "-" + groepen.getRonde() + ".docx"; File outputFile = new File(filename); FileOutputStream outFile = new FileOutputStream(outputFile); document.write(outFile); // Close output file document.close(); outFile.close(); // And open it in the system editor //Desktop.getDesktop().open(new File(outputFile)); return true; } catch (Exception ex) { logger.log(Level.WARNING, "Export mislukt :" + ex.getMessage()); Utils.stacktrace(ex); return false; } }
From source file:offishell.word.WordHeleper.java
License:MIT License
/** * <p>/*from w w w. j a v a 2 s . c o m*/ * Helper method to clone {@link XWPFRun}. * </p> * * @param in * @param out * @param model */ public static void copy(XWPFRun in, XWPFRun out, UnaryOperator<String> converter) { // copy out.setBold(in.isBold()); out.setCapitalized(in.isCapitalized()); out.setCharacterSpacing(in.getCharacterSpacing()); out.setColor(in.getColor()); out.setDoubleStrikethrough(in.isDoubleStrikeThrough()); out.setEmbossed(in.isEmbossed()); out.setFontFamily(in.getFontFamily()); out.setFontSize(in.getFontSize()); out.setImprinted(in.isImprinted()); out.setItalic(in.isItalic()); out.setKerning(in.getKerning()); out.setShadow(in.isShadowed()); out.setSmallCaps(in.isSmallCaps()); out.setStrikeThrough(in.isStrikeThrough()); out.setVerticalAlignment(out.getVerticalAlignment().toString()); out.setTextPosition(in.getTextPosition()); out.setUnderline(in.getUnderline()); // copy context CTR inCTR = in.getCTR(); CTRPr inPR = inCTR.getRPr(); CTR outCTR = out.getCTR(); CTRPr outPR = outCTR.isSetRPr() ? outCTR.getRPr() : outCTR.addNewRPr(); outPR.set(inCTR.getRPr()); out.setVerticalAlignment( inPR == null || inPR.getVertAlign() == null ? "baseline" : inPR.getVertAlign().toString()); // // copy tab // CTEmpty[] tabs = inCTR.getTabArray(); // // if (tabs.length != 0) { // out.addTab(); // } outCTR.setAnnotationRefArray(inCTR.getAnnotationRefList().toArray(CTEmpty[]::new)); outCTR.setBrArray(inCTR.getBrList().toArray(CTBr[]::new)); outCTR.setCommentReferenceArray(inCTR.getCommentReferenceList().toArray(CTMarkup[]::new)); outCTR.setContinuationSeparatorArray(inCTR.getContinuationSeparatorList().toArray(CTEmpty[]::new)); outCTR.setCrArray(inCTR.getCrList().toArray(CTEmpty[]::new)); outCTR.setDelInstrTextArray(inCTR.getDelInstrTextList().toArray(CTText[]::new)); outCTR.setDrawingArray(inCTR.getDrawingList().toArray(CTDrawing[]::new)); outCTR.setEndnoteRefArray(inCTR.getEndnoteRefList().toArray(CTEmpty[]::new)); outCTR.setFldCharArray(inCTR.getFldCharList().toArray(CTFldChar[]::new)); outCTR.setFootnoteRefArray(inCTR.getFootnoteRefList().toArray(CTEmpty[]::new)); outCTR.setInstrTextArray(inCTR.getInstrTextList().toArray(CTText[]::new)); outCTR.setLastRenderedPageBreakArray(inCTR.getLastRenderedPageBreakList().toArray(CTEmpty[]::new)); outCTR.setObjectArray(inCTR.getObjectList().toArray(CTObject[]::new)); outCTR.setPictArray(inCTR.getPictList().toArray(CTPicture[]::new)); outCTR.setPtabArray(inCTR.getPtabList().toArray(CTPTab[]::new)); outCTR.setSymArray(inCTR.getSymList().toArray(CTSym[]::new)); outCTR.setTabArray(inCTR.getTabList().toArray(CTEmpty[]::new)); // copy image for (XWPFPicture inPicture : in.getEmbeddedPictures()) { try { XWPFPictureData inData = inPicture.getPictureData(); String outId = out.getDocument().addPictureData(new ByteArrayInputStream(inData.getData()), inData.getPictureType()); select(CTBlip.class, outCTR).to(blip -> blip.setEmbed(outId)); } catch (Exception e) { throw I.quiet(e); } } // copy text write(out, converter.apply(in.text())); }
From source file:org.articleEditor.insertContent.DocumentUpdater1.java
License:Apache License
public void applyAttributes(XWPFRun run, AttributeSet attributes) { Enumeration attributeNames = attributes.getAttributeNames(); while (attributeNames.hasMoreElements()) { Object attributeName = attributeNames.nextElement(); Object attributeValue = attributes.getAttribute(attributeName); if (attributeName == Bold) { run.setBold((Boolean) attributeValue); } else if (attributeName == Italic) { run.setItalic((Boolean) attributeValue); } else if (attributeName == Underline) { run.setUnderline((Boolean) attributeValue ? UnderlinePatterns.SINGLE : UnderlinePatterns.NONE); } else if (attributeName == FontFamily || attributeName == Family) { run.setFontFamily((String) attributeValue); } else if (attributeName == FontSize) { run.setFontSize(((Number) attributeValue).intValue()); } else if (attributeName == Foreground) { Color color = (Color) attributeValue; String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); run.setColor(rgb);//from w ww . ja va 2 s.c om } else if (attributeName == Background) { Color color = (Color) attributeValue; String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); //run.getCTR().getRPr().setHighlight(); } else if (attributeName == Subscript) { run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUBSCRIPT : VerticalAlign.BASELINE); } else if (attributeName == Superscript) { run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUPERSCRIPT : VerticalAlign.BASELINE); } else if (attributeName == StrikeThrough) { run.setStrike((Boolean) attributeValue); } else if (attributeName == Alignment) { ParagraphAlignment alignment = documentToPOI((Integer) attributeValue); run.getParagraph().setAlignment(alignment); } } }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
/** * Head 1 Title/*from ww w.j a v a2 s. c o m*/ * * @param h1 * @param text */ public void textHead1Title(XWPFParagraph h1, String text) { h1.setAlignment(ParagraphAlignment.BOTH); XWPFRun h1Run = h1.createRun(); this.addParagraphTextBreak(h1Run, text); h1Run.setColor(TITLE_FONT_COLOR); h1Run.setBold(true); h1Run.setFontFamily(FONT_TYPE); h1Run.setFontSize(16); }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void textHead2Title(XWPFParagraph h2, String text) { h2.setAlignment(ParagraphAlignment.BOTH); XWPFRun h2Run = h2.createRun(); this.addParagraphTextBreak(h2Run, text); h2Run.setColor(TITLE_FONT_COLOR);/* w ww . j av a 2s. c o m*/ h2Run.setBold(true); h2Run.setFontFamily(FONT_TYPE); h2Run.setFontSize(14); }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void textHead3Title(XWPFParagraph h2, String text) { h2.setAlignment(ParagraphAlignment.BOTH); XWPFRun h2Run = h2.createRun(); this.addParagraphTextBreak(h2Run, text); h2Run.setColor(TITLE_FONT_COLOR);//from w w w .j av a2 s . co m h2Run.setBold(true); h2Run.setFontFamily(FONT_TYPE); h2Run.setFontSize(12); }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void textHeadCoverTitle(XWPFParagraph h1, String text) { h1.setAlignment(ParagraphAlignment.CENTER); XWPFRun h1Run = h1.createRun(); this.addParagraphTextBreak(h1Run, text); h1Run.setColor(TEXT_FONT_COLOR);/*www . j a va 2s. c o m*/ h1Run.setBold(false); h1Run.setFontFamily(FONT_TYPE); h1Run.setFontSize(26); }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void textNotes(XWPFParagraph paragraph, String text) { paragraph.setAlignment(ParagraphAlignment.BOTH); XWPFRun paragraphRun = paragraph.createRun(); this.addParagraphTextBreak(paragraphRun, text); paragraphRun.setColor(TEXT_FONT_COLOR); paragraphRun.setBold(false);/*from www . java2s .c o m*/ paragraphRun.setFontFamily(FONT_TYPE); paragraphRun.setFontSize(10); }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void textParagraph(XWPFParagraph paragraph, String text) { paragraph.setAlignment(ParagraphAlignment.BOTH); XWPFRun paragraphRun = paragraph.createRun(); this.addParagraphTextBreak(paragraphRun, text); paragraphRun.setColor(TEXT_FONT_COLOR); paragraphRun.setBold(false);// ww w . j a v a2 s . c om paragraphRun.setFontFamily(FONT_TYPE); paragraphRun.setFontSize(11); }