List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun setBold
@Override public void setBold(boolean value)
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 www . jav a2s .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("??? " + "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:edu.gatech.pmase.capstone.awesome.impl.output.DisasterResponseTradeStudyOutputer.java
License:Open Source License
/** * Creates the report details paragraph. * * @param xdoc the document to create the paragraph in *//*w ww .java 2 s . c om*/ private void createReportDetails(final XWPFDocument xdoc) { final Locale currentLocale = Locale.getDefault(); LOGGER.debug("Creating report details"); final XWPFParagraph para = xdoc.getParagraphs().get(REPORT_DETAILS_ROW_INDEX); final XWPFRun run1 = para.createRun(); run1.setBold(true); run1.setText("Date Report Generated: "); final XWPFRun run2 = para.createRun(); run2.setBold(false); run2.setText(outputFileFormatter.format(now)); run2.addBreak(); final XWPFRun run3 = para.createRun(); run3.setBold(true); run3.setText("Country Report Generated: "); final XWPFRun run4 = para.createRun(); run4.setBold(false); run4.setText(currentLocale.getDisplayCountry()); }
From source file:eremeykin.pete.reports.ui.ReportAction.java
@Override public void actionPerformed(ActionEvent e) { resultChanged(null);//from w w w . j a v a 2 s .c om if (model == null) { return; } XWPFDocument doc = new XWPFDocument(); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setVerticalAlignment(TextAlignment.TOP); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText(""); r1.setBold(true); r1.setFontFamily("Times New Roman"); r1.setFontSize(24); r1.setTextPosition(10); XWPFParagraph p2 = doc.createParagraph(); p2.setAlignment(ParagraphAlignment.LEFT); p2.setVerticalAlignment(TextAlignment.CENTER); XWPFRun r2 = p2.createRun(); r2.setText(" ? : "); r2.setBold(false); r2.setFontFamily("Times New Roman"); r2.setFontSize(14); r2.setTextPosition(10); XWPFTable table = doc.createTable(1, 2); table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(9000)); ModelParameter root = model.getRoot(); int row = 1; Map.Entry<ModelParameter, Integer> kv = model.getParameterAndLevelByID(root, 0); ModelParameter parameter = kv.getKey(); Integer level = kv.getValue(); ArrayList<Integer> ids = new ArrayList(model.asMap().keySet()); Collections.sort(ids); for (Integer each : ids) { table.createRow(); String text = ""; kv = model.getParameterAndLevelByID(root, each); parameter = kv.getKey(); level = kv.getValue(); for (int c = 0; c < level; c++) { text += " "; } table.getRow(row - 1).getCell(0).setText(text + parameter.toString()); table.getRow(row - 1).getCell(1).setText(parameter.getValue()); row++; } table.setWidth(80); XWPFParagraph p3 = doc.createParagraph(); p3.setAlignment(ParagraphAlignment.LEFT); p3.setVerticalAlignment(TextAlignment.CENTER); XWPFRun r3 = p3.createRun(); r3.addBreak(); r3.setText("\n : "); r3.setBold(false); r3.setFontFamily("Times New Roman"); r3.setFontSize(14); File uPlotFile = new File(WorkspaceManager.INSTANCE.getWorkspace().getAbsolutePath() + "/uplot.png"); try { byte[] picbytes = IOUtils.toByteArray(new FileInputStream(uPlotFile)); doc.addPictureData(picbytes, XWPFDocument.PICTURE_TYPE_PNG); XWPFRun pr = doc.createParagraph().createRun(); pr.addPicture(new FileInputStream(uPlotFile), Document.PICTURE_TYPE_PNG, "plot.png", Units.toEMU(450), Units.toEMU(337)); pr.addCarriageReturn(); pr.addBreak(BreakType.PAGE); pr.addBreak(BreakType.TEXT_WRAPPING); } catch (Exception ex) { Exceptions.printStackTrace(ex); } XWPFParagraph p4 = doc.createParagraph(); p4.setAlignment(ParagraphAlignment.LEFT); p4.setVerticalAlignment(TextAlignment.CENTER); XWPFRun r4 = p4.createRun(); r4.addBreak(); r4.setText("\n ?: "); r4.setBold(false); r4.setFontFamily("Times New Roman"); r4.setFontSize(14); File sPlotFile = new File(WorkspaceManager.INSTANCE.getWorkspace().getAbsolutePath() + "/splot.png"); try { byte[] picbytes = IOUtils.toByteArray(new FileInputStream(sPlotFile)); doc.addPictureData(picbytes, XWPFDocument.PICTURE_TYPE_PNG); XWPFParagraph pp = doc.createParagraph(); pp.createRun().addPicture(new FileInputStream(sPlotFile), Document.PICTURE_TYPE_PNG, "plot.png", Units.toEMU(450), Units.toEMU(337)); } catch (Exception ex) { Exceptions.printStackTrace(ex); } File reportFile = new File("report.docx"); try (FileOutputStream out = new FileOutputStream(reportFile)) { doc.write(out); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().edit(reportFile); } else { } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
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);//w w w. j a va 2 s . com 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:library.Form_Library.java
private void btPrintReaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPrintReaderActionPerformed try {/*from w w w .ja v a2s .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:MainPackage.Controllers.BookController.java
private XWPFRun createValueRun(XWPFParagraph paragraph, String text) { XWPFRun run = createRun(paragraph, text); run.setBold(false); return run; }
From source file:MainPackage.Controllers.BookController.java
private XWPFRun createFieldRun(XWPFParagraph paragraph, String text) { XWPFRun run = createRun(paragraph, text); run.setBold(true); return run; }
From source file:Management.Projects.java
public String CrearMinuta(String datos[], int idProject, String[] Asistentes, String[] puntos) throws IOException { String result = ""; ArrayList<XWPFParagraph> listfecha = new ArrayList<>(); ArrayList<XWPFParagraph> listasistentes = new ArrayList<>(); ArrayList<XWPFParagraph> listpuntos = new ArrayList<>(); XWPFDocument doc = new XWPFDocument(); int i;// w ww . j a va2 s . c om XWPFParagraph p3; XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setBorderBottom(Borders.DOUBLE); p1.setBorderTop(Borders.DOUBLE); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText("Datos de la minuta"); r1.setBold(true); for (i = 0; i < datos.length; i++) { p3 = doc.createParagraph(); listfecha.add(p3); } i = 0; for (XWPFParagraph para : listfecha) { XWPFRun r2 = para.createRun(); r2.setText(datos[i]); r2.setFontSize(20); i++; } XWPFParagraph parrafoAsistentes = doc.createParagraph(); parrafoAsistentes.setAlignment(ParagraphAlignment.CENTER); parrafoAsistentes.setBorderBottom(Borders.DOUBLE); parrafoAsistentes.setBorderTop(Borders.DOUBLE); XWPFRun r2 = parrafoAsistentes.createRun(); r2.setBold(true); r2.setText("Asistentes:"); r2.setBold(true); XWPFParagraph p4; for (i = 0; i < Asistentes.length; i++) { p4 = doc.createParagraph(); listasistentes.add(p4); } i = 0; for (XWPFParagraph para : listasistentes) { XWPFRun r3 = para.createRun(); r3.setText(Asistentes[i]); r3.setFontSize(20); i++; } XWPFParagraph parrafoPuntos = doc.createParagraph(); parrafoPuntos.setAlignment(ParagraphAlignment.CENTER); parrafoPuntos.setBorderBottom(Borders.DOUBLE); parrafoPuntos.setBorderTop(Borders.DOUBLE); XWPFRun r3 = parrafoPuntos.createRun(); r3.setBold(true); r3.setText("Puntos a Tratar:"); r3.setBold(true); XWPFParagraph p5; for (i = 0; i < puntos.length; i++) { p5 = doc.createParagraph(); listpuntos.add(p5); } i = 0; for (XWPFParagraph para : listpuntos) { XWPFRun r4 = para.createRun(); r4.setText(puntos[i]); r4.setFontSize(20); i++; } FileOutputStream out = null; try { out = new FileOutputStream(System.getProperty("user.home") + "/Documents/NetBeansProjects/StickMaps/web/Minutas/Minuta" + idProject + ".docx"); } catch (FileNotFoundException ex) { System.out.println(ex.toString()); return ex.toString(); } doc.write(out); result = "bien"; out.close(); return result; }
From source file:nl.architolk.ldt.processors.WordSerializer.java
License:Open Source License
protected void readInput(final PipelineContext pipelineContext, final ProcessorInput input, Config config, OutputStream outputStream) { try {//from w w w. j a va2 s. c o m // Test BigInteger markId = BigInteger.ONE; // Read the input as a DOM final Document domDocument = readInputAsDOM(pipelineContext, input); // create document (docx) XWPFDocument doc = new XWPFDocument(); //iterate through paragraphs; NodeList paragraphNodes = domDocument.getElementsByTagName("p"); for (short i = 0; i < paragraphNodes.getLength(); i++) { Node paragraphNode = paragraphNodes.item(i); if (paragraphNode.getNodeType() == Node.ELEMENT_NODE) { //Create new paragraph XWPFParagraph paragraph = doc.createParagraph(); //iterate through paragraph parts NodeList textNodes = paragraphNode.getChildNodes(); for (short r = 0; r < textNodes.getLength(); r++) { Node textNode = textNodes.item(r); if (textNode.getNodeType() == Node.TEXT_NODE) { XWPFRun run = paragraph.createRun(); run.setText(textNode.getTextContent()); } if (textNode.getNodeType() == Node.ELEMENT_NODE) { Element textElement = (Element) textNode; if (textNode.getLocalName().toUpperCase().equals("B")) { //Eigenlijk op een andere plaats, maar nu ff voor de test String anchor = textElement.getAttribute("id"); if (!anchor.isEmpty()) { CTBookmark bookStart = paragraph.getCTP().addNewBookmarkStart(); bookStart.setName(anchor); bookStart.setId(markId); } XWPFRun run = paragraph.createRun(); run.setBold(true); run.setText(textNode.getTextContent()); if (!anchor.isEmpty()) { CTMarkupRange bookEnd = paragraph.getCTP().addNewBookmarkEnd(); bookEnd.setId(markId); markId = markId.add(BigInteger.ONE); } } else if (textNode.getLocalName().toUpperCase().equals("A")) { addHyperlink(paragraph, textNode.getTextContent(), textElement.getAttribute("href")); } else { XWPFRun run = paragraph.createRun(); run.setText(textNode.getTextContent()); } } } } } // write workbook to stream doc.write(outputStream); outputStream.close(); } catch (Exception e) { throw new OXFException(e); } }
From source file:offishell.word.WordHeleper.java
License:MIT License
/** * <p>/*from w ww . j a v a2 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())); }