List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun setColor
public void setColor(String rgbStr)
From source file:certificatecreator.CertificateCreator.java
private void createStudentCertificate(String tempPath) { //Creates student certificate. //Read in template file and define output file. File inFile = new File(tempPath); File outFile = new File(userPath + File.separator + selectedStudent + "Certificate.docx"); //Create output file. Throw alert if tempPath references nonexisting file. try {/*from w ww . j a v a 2 s . c o m*/ copy(inFile, outFile); //Create internal word document based on copied template file. Write content. try { XWPFDocument certificate = new XWPFDocument(new FileInputStream(outFile)); XWPFParagraph p1 = certificate.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); XWPFRun r1 = p1.createRun(); r1.setFontFamily("Candara"); r1.setFontSize(40); r1.addBreak(); r1.setText("Lawton Elementary Congratulates"); XWPFRun r2 = p1.createRun(); r2.setFontFamily("Candara"); r2.setFontSize(36); r2.setBold(true); r2.addBreak(); r2.addBreak(); r2.setText(selectedStudent); r2.addBreak(); r2.addBreak(); XWPFRun r3 = p1.createRun(); r3.setFontFamily("Candara"); r3.setFontSize(26); r3.setText("For being a Lawton CARES winner on"); r3.addBreak(); String date = getDate(); r3.setText(date); r3.addBreak(); r3.addBreak(); r3.addBreak(); r3.addBreak(); XWPFRun r4 = p1.createRun(); r4.setColor("5B9BD5"); r4.setFontFamily("Candara"); r4.setFontSize(26); r4.setText("Compassion+Attitude+Respect+Effort+Safety=CARES"); //Write internal document to copied templated file. try { FileOutputStream out = new FileOutputStream(outFile.toString()); try { certificate.write(out); out.close(); } catch (IOException io) { System.err.println("Could not write file: " + io); } } catch (FileNotFoundException fnf) { System.err.println("Could not find output file: " + fnf); } } catch (IOException io) { System.err.println("Copy of template could not be found: " + io); } } catch (IOException io) { System.err.println("Method copy failed:" + io); } catch (NullPointerException npe) { System.err.println("Method copy failed:" + npe); Alert templateNotFound = new Alert(AlertType.WARNING, "Specified certificate template was not found. " + "Please choose a different template."); templateNotFound.showAndWait(); } }
From source file:com.deepoove.poi.policy.TextRenderPolicy.java
License:Apache License
private void styleRun(XWPFRun run, Style style) { if (null != style) { String color = style.getColor(); String fontFamily = style.getFontFamily(); int fontSize = style.getFontSize(); Boolean bold = style.isBold(); Boolean italic = style.isItalic(); Boolean strike = style.isStrike(); if (null != color) run.setColor(color); if (0 != fontSize) run.setFontSize(fontSize);// ww w .j a va2 s. c om if (null != fontFamily) run.setFontFamily(fontFamily); if (null != bold) run.setBold(bold); if (null != italic) run.setItalic(italic); if (null != strike) run.setStrike(strike); } }
From source file:com.deepoove.poi.resolver.TemplateResolver.java
License:Apache License
private static void styleRun(XWPFRun destRun, XWPFRun srcRun) { if (null == destRun || null == srcRun) return;//from w ww . j ava 2s . c o m destRun.setBold(srcRun.isBold()); destRun.setColor(srcRun.getColor()); destRun.setFontFamily(srcRun.getFontFamily()); int fontSize = srcRun.getFontSize(); if (-1 != fontSize) destRun.setFontSize(fontSize); destRun.setItalic(srcRun.isItalic()); destRun.setStrike(srcRun.isStrike()); destRun.setUnderline(srcRun.getUnderline()); }
From source file:de.knowwe.include.export.InlineDefinitionExporter.java
License:Open Source License
@Override public void export(Section<InlineDefinitionType> section, DocumentBuilder manager) throws ExportException { ExportUtils.addRequiredSpace(manager); String refID = HeaderExporter.getCrossReferenceID(section); XWPFRun run = HeaderExporter.createCrossReferenceRun(refID, manager); run.setColor("606060"); run.setFontSize(7);/* w ww. ja va2 s . c om*/ run.setText("("); run.setText(section.get().getHeadText(section)); run.setText(": "); manager.export(section.get().getDataSection(section)); run = manager.getParagraph().createRun(); run.setColor("606060"); run.setFontSize(7); run.setText(")"); run = manager.getParagraph().createRun(); run.setText(" "); }
From source file:edu.gatech.pmase.capstone.awesome.impl.output.DisasterResponseTradeStudyOutputer.java
License:Open Source License
/** * Creates output for architecture options if no architecture was found. * * @param label the cell with the label//from w w w. ja v a 2 s . co m * @param optionName the name of the option to place */ private static void createNoOptionText(final XWPFTableCell label, final String optionName) { LOGGER.debug("Creationg No Option Text for option: " + optionName); final XWPFParagraph platPara = label.getParagraphs().get(0); final XWPFRun rh = platPara.createRun(); rh.setColor(DisasterResponseTradeStudyOutputer.NO_OPT_TEXT_COLOR); rh.setText("No " + optionName + " Satisfies Selections"); platPara.setAlignment(ParagraphAlignment.CENTER); }
From source file:export.TableFunctionalReq.java
protected static void createReqFuncTable(XWPFDocument doc, FunctionalRequirement funcReq) { int[] cols = { 2943, 6507 }; XWPFTable rf = doc.createTable(9, 2); // Get a list of the rows in the table List<XWPFTableRow> rows = rf.getRows(); int rowCt = 0; int colCt = 0; for (XWPFTableRow row : rows) { // get the cells in this row List<XWPFTableCell> cells = row.getTableCells(); for (XWPFTableCell cell : cells) { // get a table cell properties element (tcPr) CTTcPr tcpr = cell.getCTTc().addNewTcPr(); // create cell color element CTShd ctshd = tcpr.addNewShd(); ctshd.setColor("auto"); ctshd.setVal(STShd.CLEAR);//from www. ja v a2s .c o m if (colCt == 0) { ctshd.setFill("5C7F92"); } // get 1st paragraph in cell's paragraph list XWPFParagraph para = cell.getParagraphs().get(0); para.setStyle("AltranNormal"); para.setSpacingAfter(120); para.setSpacingBefore(120); // create a run to contain the content XWPFRun rh = para.createRun(); //rh.setFontSize(11); rh.setFontFamily("Lucida Sans Unicode"); if (colCt == 0) { rh.setColor("FFFFFF"); } if (rowCt == 0 && colCt == 0) { rh.setText("RF " + ((x < 9) ? "0" + x : x) + "- F"); x++; } else if (rowCt == 1 && colCt == 0) { rh.setText("Use Case (se disponvel):"); } else if (rowCt == 2 && colCt == 0) { rh.setText("Descrio:"); } else if (rowCt == 3 && colCt == 0) { rh.setText("Fonte:"); } else if (rowCt == 4 && colCt == 0) { rh.setText("Fundamento:"); } else if (rowCt == 5 && colCt == 0) { rh.setText("Critrio de avaliao:"); } else if (rowCt == 6 && colCt == 0) { rh.setText("Satisfao do cliente:"); } else if (rowCt == 7 && colCt == 0) { rh.setText("Insatisfao do cliente:"); } else if (rowCt == 8 && colCt == 0) { rh.setText("Histrico:"); } if (rowCt == 0 && colCt == 1) {// Nome do requisito rh.setText(funcReq.getName()); rh.setBold(true); } else if (rowCt == 1 && colCt == 1) { // UseCases String testUC = ""; int cntUC = 0; for (UseCase uc : funcReq.getUseCaseCollection()) { if (cntUC == 0) { testUC = uc.getName(); } else { testUC = testUC + ", " + uc.getName(); } cntUC++; } rh.setText(testUC); } else if (rowCt == 2 && colCt == 1) {// Descrio rh.setText(funcReq.getDescription()); } else if (rowCt == 3 && colCt == 1) {// Fonte rh.setText(funcReq.getSource()); } else if (rowCt == 4 && colCt == 1) {// Fundamento rh.setText(funcReq.getReason()); } else if (rowCt == 5 && colCt == 1) {// Criterio de Avalicao rh.setText(funcReq.getAvaliationCriteria()); } else if (rowCt == 6 && colCt == 1) {// Prioridade rh.setText(funcReq.getClientPriority().toString()); } else if (rowCt == 7 && colCt == 1) {// Insatisfao rh.setText(funcReq.getClientInsatisfaction().toString()); } else if (rowCt == 8 && colCt == 1) {// Historico rh.setText("Histrico"); } cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[colCt])); colCt++; } colCt = 0; rowCt++; } doc.createParagraph().createRun().addBreak(); }
From source file:offishell.word.WordHeleper.java
License:MIT License
/** * <p>/*from w w w . j av 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); } 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); }// w ww . j a va 2 s .c o m } }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
/** * Head 1 Title//from w w w . j a v a 2s . 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); h2Run.setBold(true);/* w w w. j a va 2s . co m*/ h2Run.setFontFamily(FONT_TYPE); h2Run.setFontSize(14); }