List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun setText
public void setText(String value)
From source file:IsiXhosa_spellchecker.Spellchecker.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // Save file being edited to machine int len = textArea.getText().length(); boolean English = jRadioButton1.isSelected(); if (len == 0) { if (English) { instruction.setText("You are trying to save an empty file!"); instruction.setForeground(Color.RED); } else {/*w w w . j a v a2 s . c om*/ instruction.setText("Uzama ukugcina ifayile engenanto!"); instruction.setForeground(Color.RED); } //System.out.println(data); } else { int returnVal = fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { // What to do with the file, e.g. display it in a TextArea if (highlightSet) { highlighter.removeAllHighlights(); } if (file.getName().endsWith(".docx")) { XWPFDocument document = new XWPFDocument(); XWPFParagraph tmpParagraph = document.createParagraph(); XWPFRun tmpRun = tmpParagraph.createRun(); tmpRun.setText(textArea.getText()); tmpRun.setFontSize(12); document.write(new FileOutputStream(new File(file.getPath()))); } else { textArea.write(new FileWriter(file.getAbsolutePath()));//this file has no extension } } catch (IOException ex) { System.out.println("problem accessing file" + file.getAbsolutePath()); } } } }
From source file:isizulu_spellchecker.Spellchecker.java
private void saveAsAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsAsActionPerformed // TODO add your handling code here: int returnVal = fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try {//from www. ja v a 2 s.c o m // What to do with the file, e.g. display it in a TextArea if (highlightSet) { highlighter.removeAllHighlights(); } if (file.getName().endsWith(".docx")) { XWPFDocument document = new XWPFDocument(); XWPFParagraph tmpParagraph = document.createParagraph(); XWPFRun tmpRun = tmpParagraph.createRun(); tmpRun.setText(textArea.getText()); tmpRun.setFontSize(12); document.write(new FileOutputStream(new File(file.getPath()))); } else { textArea.write(new FileWriter(file.getAbsolutePath()));//this file has no extension } } catch (IOException ex) { System.out.println("problem accessing file" + file.getAbsolutePath()); } } }
From source file:library.Form_Library.java
private void btPrintReaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPrintReaderActionPerformed try {//from w w w . j a va 2s .c o 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 createRun(XWPFParagraph paragraph, String text) { XWPFRun run; run = paragraph.createRun();//w w w . j a v a2 s . co m run.setText(text); run.addTab(); 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;//from ww w . jav a2 s . co m 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:Management.PruebaDoc.java
public static void main(String[] args) throws IOException { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p3 = doc.createParagraph(); XWPFRun r4 = p3.createRun(); r4.setTextPosition(20);/*from ww w. j a va 2 s . c o m*/ 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); FileOutputStream out = null; try { out = new FileOutputStream( "C:\\Users\\hilsierivan\\Documents\\NetBeansProjects\\StickMaps\\web\\MapImages\\simple.docx"); } catch (FileNotFoundException ex) { Logger.getLogger(PruebaDoc.class.getName()).log(Level.SEVERE, null, ex); } doc.write(out); out.close(); }
From source file:msoffice.ReadWord.java
public static void main(String[] args) { try {//ww w . ja va 2 s. co m FileInputStream fis = new FileInputStream("H:\\OFICIOTEMPLATE.docx"); XWPFDocument docx = new XWPFDocument(fis); List<XWPFParagraph> paragraphList = docx.getParagraphs(); int nump = paragraphList.size(); System.out.println(nump); for (int x = 0; x < paragraphList.size(); x++) { } for (XWPFParagraph paragraph : paragraphList) { String text = paragraph.getText(); XWPFRun rh = paragraph.createRun(); if (text.contains("unidad")) { text = text.replace("unidad", "CICTE/W-6.a/02.00"); paragraph.removeRun(8); rh.setText(text); } if (text.contains("receptor")) { text = text.replace("receptor", "Gral Brig Jefe del Servicio de Material de Guerra del Ejrcito"); } if (text.contains("asunto")) { text = text.replace("asunto", "Sobre articulo de MG (Armamento) y apoyo de elemento tecnico."); } if (text.contains("referencia")) { text = text.replace("referencia", "Oficio N289/CICTE del 01 julio de 2015."); } if (text.contains("cuerpo")) { text = text.replace("cuerpo", "Tengo el honor de dirigirme a Ud., para manifestarle que en relacin a la solicitud de prestamo de una (01) ametralladora BROWNING Cal .50 y la participacin del elemento tcnico Tco 2da MAM Pacheco Tejada Henry, para las pruebas del vehculo blindado OTORONGO, las cuales se han suspendido y sern reprogramadas.\n" + "Asimismo, se informar de manera oportuna la fecha de realizacin de las pruebas del vehculo blindado OTORONGO, para poder contar con artculo de MG (Armamento) y apoyo de elemento tcnico solicitado.\n" + "Hago propicia la oportunidad para expresarle a Ud. los sentimientos de mi especial consideracin y estima personal."); } System.out.println(text); docx.write(new FileOutputStream("OFICIO.docx")); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
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 www.j a v a2s . 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:nl.detoren.ijc.io.OutputIntekenlijst.java
License:Open Source License
public boolean export(Groepen groepen) { try {//from w w w. j a v a 2 s . c om 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.Word.java
License:MIT License
/** * <p>// ww w . j ava 2s . c o m * Create header with the specified text. * </p> * * @param headerText A header text. */ public Word header(String headerText) { try { CTSectPr section = calculated.getDocument().getBody().addNewSectPr(); XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(calculated, section); XWPFHeader header = policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT); XWPFParagraph para = header.createParagraph(); XWPFRun run = para.createRun(); run.setText(headerText); styles().base().apply(run); } catch (Exception e) { throw I.quiet(e); } return this; }