List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph getText
public String getText()
From source file:File.DOCX.ReadDocx.java
/** * @param args the command line arguments *///from w w w . java 2s . c om public void ReadParagraph(String path, String filename) { try { FileInputStream fis = new FileInputStream(path + filename + ".docx"); XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis)); List<XWPFParagraph> paragraphList = xdoc.getParagraphs(); for (XWPFParagraph paragraph : paragraphList) { System.out.println(paragraph.getText()); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:fr.opensagres.poi.xwpf.converter.core.styles.A.java
License:Open Source License
private void testParagraph(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) { Float spacingAfter = stylesDocument.getSpacingAfter(paragraph); if (paragraph.getText().startsWith("Cette commande client est co")) { testParagraphWithTitre(paragraph, stylesDocument); }/*from www .j a v a 2s . c o m*/ }
From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java
License:Open Source License
private void testTableCell(XWPFTableCell cell, XWPFStylesDocument stylesDocument) { XWPFParagraph paragraph = cell.getParagraphs().get(0); if ("A".equals(paragraph.getText())) { testsA(paragraph, stylesDocument); } else if ("B".equals(paragraph.getText())) { testsB(paragraph, stylesDocument); } else if ("C".equals(paragraph.getText())) { testsC(paragraph, stylesDocument); } else if ("D".equals(paragraph.getText())) { testsD(paragraph, stylesDocument); } else if ("E".equals(paragraph.getText())) { testsE(paragraph, stylesDocument); } else if ("F".equals(paragraph.getText())) { testsF(paragraph, stylesDocument); } else if ("G".equals(paragraph.getText())) { testsG(paragraph, stylesDocument); } else if ("H".equals(paragraph.getText())) { testsH(paragraph, stylesDocument); } else if ("I".equals(paragraph.getText())) { testsI(paragraph, stylesDocument); }// w ww . j ava2s .com }
From source file:IsiXhosa_spellchecker.Spellchecker.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // Open file from machine int returnVal = fileChooser.showOpenDialog(this); boolean English = jRadioButton1.isSelected(); if (English)/* ww w . j a v a 2s .c o m*/ instruction.setText("Spellcheck to check for errors"); else instruction.setText("Cofa uSebenzisa ukuze uhlole amaphutha"); instruction.setForeground(Color.BLUE); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); String name = file.getName(); String ext = name.substring(name.indexOf("."), name.length()); try { // What to do with the file, e.g. display it in a TextArea if (highlightSet) { highlighter.removeAllHighlights(); } if (name.endsWith(".docx")) { FileInputStream fis = new FileInputStream(file.getAbsolutePath()); XWPFDocument docx = new XWPFDocument(fis); List<XWPFParagraph> pars = docx.getParagraphs(); String toDisplay = ""; for (XWPFParagraph para : pars) { toDisplay += para.getText() + "\n"; } textArea.setText(toDisplay); text = textArea.getText(); } else { textArea.read(new FileReader(file.getAbsolutePath()), null); text = textArea.getText(); //for controlling the displayed text } } catch (IOException ex) { System.out.println("problem accessing file" + file.getAbsolutePath()); } } //Resets globals used by other buttons such as ignoreAll pos = 0; sentNo = 0; wordNo = 0; }
From source file:isizulu_spellchecker.Spellchecker.java
private void openActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openActionPerformed // TODO add your handling code here: int returnVal = fileChooser.showOpenDialog(this); if (language) instruction.setText("Click run to check for errors"); else/*from www .j a va2s . c o m*/ instruction.setText("Cofa uSebenzisa ukuze uhlole amaphutha"); instruction.setForeground(Color.BLUE); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); String name = file.getName(); String ext = name.substring(name.indexOf("."), name.length()); try { // What to do with the file, e.g. display it in a TextArea if (highlightSet) { highlighter.removeAllHighlights(); } if (name.endsWith(".docx")) { FileInputStream fis = new FileInputStream(file.getAbsolutePath()); XWPFDocument docx = new XWPFDocument(fis); List<XWPFParagraph> pars = docx.getParagraphs(); String toDisplay = ""; for (XWPFParagraph para : pars) { toDisplay += para.getText() + "\n"; } textArea.setText(toDisplay); text = textArea.getText(); } else { textArea.read(new FileReader(file.getAbsolutePath()), null); text = textArea.getText(); //for controlling the displayed text } } catch (IOException ex) { System.out.println("problem accessing file" + file.getAbsolutePath()); } } //Resets globals used by other buttons such as ignoreAll pos = 0; sentNo = 0; wordNo = 0; }
From source file:kz.service.DocumentReader.java
public static String readDocxFile(String fileName) { try {//ww w . ja va2s. c o m File file = new File(fileName); FileInputStream fis = new FileInputStream(file.getAbsolutePath()); StringBuffer content = new StringBuffer(); XWPFDocument document = new XWPFDocument(fis); XWPFStyles styles = document.getStyles(); List<XWPFParagraph> paragraphs = document.getParagraphs(); List<XWPFTable> tables = document.getTables(); List<XWPFPictureData> pictures = document.getAllPictures(); //int Picture_ID = 0; for (XWPFPictureData picture : pictures) { //XWPFPictureData picture = pictures.get(Picture_ID); System.out.println("Picture: " + picture.getFileName()); byte[] pictureData = picture.getData(); BufferedImage image = ImageIO.read(new ByteArrayInputStream(pictureData)); ImageIO.write(image, picture.getFileName(), file); content.append("<p>"); content.append("Here must be image"); content.append("</p>"); //Picture_ID++; } Iterator<IBodyElement> bodyElementIterator = document.getBodyElementsIterator(); int Table_ID = 0; int Paragraph_ID = 0; while (bodyElementIterator.hasNext()) { IBodyElement element = bodyElementIterator.next(); System.out.println(element.getElementType().name());//prints Element type name if ("TABLE".equalsIgnoreCase(element.getElementType().name())) { content.append("<table>"); XWPFTable table = tables.get(Table_ID); CTTbl cttbl = table.getCTTbl(); CTTblPr cttblPr = cttbl.getTblPr(); List<XWPFTableRow> tblRows = table.getRows(); for (XWPFTableRow tblRow : tblRows) { content.append("<tr>"); List<XWPFTableCell> tblCells = tblRow.getTableCells(); for (XWPFTableCell tblCell : tblCells) { content.append("<td>"); content.append(tblCell.getText()); content.append("</td>"); } content.append("</tr>"); } content.append("</table>"); Table_ID++; } else if ("PARAGRAPH".equalsIgnoreCase(element.getElementType().name())) { XWPFParagraph paragraph = paragraphs.get(Paragraph_ID); String styleClass = null; if (paragraph.getStyleID() != null) { content.append("<p class=''>"); XWPFStyle style = styles.getStyle(paragraph.getStyleID()); if (style != null && style.getName() != null) { //here will be code creation of tag with class style } } else { content.append("<p>"); } content.append(paragraph.getText()); content.append("</p>"); Paragraph_ID++; } } fis.close(); return content.toString(); } catch (Exception e) { return e.toString(); } }
From source file:msoffice.ReadWord.java
public static void main(String[] args) { try {/*from w ww .j a v a 2 s . com*/ 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:myexamples.WordDocsExamples.Test1.java
public static void simplepartsReading() throws IOException { JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println(chooser.getSelectedFile().getName()); FileInputStream fis = new FileInputStream(chooser.getSelectedFile()); XWPFDocument doc = new XWPFDocument(fis); XWPFWordExtractor extract = new XWPFWordExtractor(doc); //System.out.println(extract.getText()); List<XWPFParagraph> pList = doc.getParagraphs(); List<XWPFTable> tList = doc.getTables(); System.out.println("Number of Paragraphs=" + pList.size()); System.out.println("Number of Tables=" + tList.size()); List<XWPFTableRow> rList; List<XWPFTableCell> cList; List<XWPFParagraph> rcpList; int tCount = 0, rCount = 0, cCount = 0, rcpCount = 0, dummCounter = 0; WordReference wordReference = new WordReference(); for (XWPFTable t : tList) { rList = t.getRows();/*from ww w . j a v a 2 s . c o m*/ rCount = 0; cCount = 0; rcpCount = 0; System.out.println("Table Nr." + (tCount++)); for (XWPFTableRow r : rList) { cList = r.getTableCells(); cCount = 0; rcpCount = 0; System.out.println("Row Nr." + (rCount++)); for (XWPFTableCell c : cList) { rcpList = c.getParagraphs(); rcpCount = 0; System.out.println("Cell Nr." + (cCount++)); System.out.println("Cell Text: " + c.getText()); System.out.println("Nr of Tables: " + c.getTables().size()); for (XWPFParagraph rcp : rcpList) { System.out.println("Par Nr." + (rcpCount++) + " Paragraphtext=" + rcp.getText()); } for (XWPFTable t1 : c.getTables()) { for (XWPFTableRow r1 : t1.getRows()) { for (XWPFTableCell c1 : r1.getTableCells()) { System.out.println("DC Nr." + dummCounter + " Cell Text: " + c1.getText()); switch (dummCounter) { case 0: wordReference.kundenLogo = c1.getText(); break; case 1: wordReference.kundenprofil = c1.getText(); break; case 2: wordReference.ausgangslage = c1.getText(); break; case 3: wordReference.losung = c1.getText(); break; case 4: wordReference.ergebnis = c1.getText(); break; case 5: wordReference.kunde = c1.getText(); break; case 6: wordReference.projektname = c1.getText(); break; case 7: wordReference.kundenstatement = c1.getText(); break; case 8: wordReference.statementBei = c1.getText(); break; case 9: wordReference.flisstext = c1.getText(); break; default: ; } dummCounter++; } } } } } } System.out.println(wordReference.toString(1)); } }
From source file:offishell.task.Task.java
License:MIT License
/** * <p>/*from w w w . j a v a2s .co m*/ * ??? * </p> * * @return */ default Date month() { List<XWPFParagraph> paras = mainWord().paragraphs.toList(); List<String> methods = I.signal(new Error().getStackTrace()) .take(e -> e.getClassName().equals(getClass().getName())).map(e -> e.getMethodName()).toList(); XWPFStyles styles = paras.get(0).getDocument().getStyles(); String heading = ""; for (XWPFParagraph para : paras) { String text = para.getText(); String id = para.getStyleID(); if (id != null && styles.getStyle(id).getName().toLowerCase().contains("heading")) { heading = text; } if (methods.stream().anyMatch(text::contains)) { // parse heading text heading = Normalizer.normalize(heading, Form.NFKC); int start = heading.indexOf("("); int end = heading.indexOf(")"); if (start != -1 && end != -1) { heading = heading.substring(start + 1, end); Matcher matcher = Pattern.compile("((\\d+))?(\\d+).*").matcher(heading); if (matcher.matches()) { int year = matcher.group(1) == null ? LocalDate.now().getYear() : Integer.parseInt(matcher.group(2)); return Date.of(year, Integer.parseInt(matcher.group(3)), 1); } } return Date.now(); } } return Date.now(); }
From source file:orcamentotraducao.OrcamentoTraducao.java
/** * @param args the command line arguments */// w w w. j av a2s . c o m public static void main(String[] args) { // TODO code application logic here Scanner scan = new Scanner(System.in); System.out.println("Informe o nome do arquivo:"); String filename = scan.nextLine(); String typeFile = filename.substring(filename.length() - 3, filename.length()); if (!typeFile.matches("ocx") && !typeFile.matches("doc")) { System.out.println("Este formato de arquivo no suportado\n"); System.exit(0); } try { File file = new File(filename); FileInputStream fis = new FileInputStream(file.getAbsolutePath()); String allText = ""; int lines = 0; if (typeFile.matches("ocx")) { XWPFDocument document = new XWPFDocument(fis); List<XWPFParagraph> paragraphs = document.getParagraphs(); for (XWPFParagraph para : paragraphs) { allText += para.getText() + " "; lines++; } fis.close(); } else if (typeFile.matches("doc")) { WordExtractor extractor = new WordExtractor(new HWPFDocument(fis)); allText = extractor.getText(); } String allTextExploded[] = allText.split(" "); int words = allTextExploded.length; int characters = allText.length(); System.out.println("H " + words + " palavras"); System.out.println("H " + characters + " caracteres"); System.out.println("H " + lines + " linhas"); System.out.println("O oramento estimado de R$" + calculate(characters, words, lines)); } catch (Exception e) { e.printStackTrace(); } }