List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph createRun
public XWPFRun createRun()
From source file:sofmeth.mco3.gui.TRTFrame.java
private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed // TODO add your handling code here: XWPFDocument document = new XWPFDocument(); try {/* w ww. j ava 2 s . co m*/ FileOutputStream out = new FileOutputStream(new File("test report template.docx")); //making of title XWPFParagraph para = document.createParagraph(); para.setAlignment(ParagraphAlignment.CENTER); para.setSpacingAfter(500); XWPFRun run = para.createRun(); run.setText("Test Report Template"); run.setBold(true); run.setFontSize(16); //end making of title //start making name table XWPFTable details = document.createTable(2, 2); //setting cell width CTTblWidth width = details.getCTTbl().addNewTblPr().addNewTblW(); width.setType(STTblWidth.DXA); width.setW(BigInteger.valueOf(9000)); //end setting cell width //details.getCTTbl().getTblPr().unsetTblBorders(); XWPFTableRow row = details.getRow(0); row.getCell(0).setText("Name: " + nameField); row.getCell(1).setText("Date: " + nameField); row = details.getRow(1); row.getCell(0).setText("Professor: " + profField); row.getCell(1).setText("Program#: " + progNumField); para = document.createParagraph(); run = para.createRun(); run.addBreak(); run.addBreak(); //end making name table while (true) { if (trtTable.getModel().getValueAt(i, 0) != null && !trtTable.getModel().getValueAt(i, 0).toString().isEmpty()) { XWPFTable table = document.createTable(6, 2); width = table.getCTTbl().addNewTblPr().addNewTblW(); width.setType(STTblWidth.DXA); width.setW(BigInteger.valueOf(9500)); for (int j = 0; j < 6; j++) { row = table.getRow(j); switch (j) { case 0: row.getCell(0).setText("Test Number"); row.getCell(1).setText(trtTable.getModel().getValueAt(i, 0).toString()); break; case 1: row.getCell(0).setText("Test Objective"); row.getCell(1).setText(trtTable.getModel().getValueAt(i, 1).toString()); break; case 2: row.getCell(0).setText("Test Description"); row.getCell(1).setText(trtTable.getModel().getValueAt(i, 2).toString()); break; case 3: row.getCell(0).setText("Test Conditions"); row.getCell(1).setText(trtTable.getModel().getValueAt(i, 3).toString()); break; case 4: row.getCell(0).setText("Expected Results"); row.getCell(1).setText(trtTable.getModel().getValueAt(i, 4).toString()); break; case 5: row.getCell(0).setText("Actual Results"); row.getCell(1).setText(trtTable.getModel().getValueAt(i, 5).toString()); break; } } para = document.createParagraph(); run = para.createRun(); run.addBreak(); run.addBreak(); i++; } else break; } document.write(out); out.close(); } catch (Exception e) { } }
From source file:src.controller.DocumentController.java
public void convertToDocX(File filepath, File filename) { PDDocument documentpdf;/*from w ww.j av a 2 s . c om*/ try { documentpdf = PDDocument.load(filepath); PDFTextStripper pdfStripper = new PDFTextStripper(); pdfStripper.setStartPage(1); //pdfStripper.setEndPage( 1 ); String parsedText = pdfStripper.getText(documentpdf); System.out.println(parsedText); // enregistrement du document dans un fichier FileOutputStream out = new FileOutputStream(filepath + filename.toString() + ".docx"); XWPFDocument document = new XWPFDocument(); //create Paragraph XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.setText(parsedText); document.write(out); out.close(); } catch (IOException ex) { Logger.getLogger(DocumentController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:storemanager.models.Output.java
public void printRecipes(ArrayList<OutputStringLine> list) { try {//from ww w. j a v a 2s . c o m SimpleDateFormat sdfDate = new SimpleDateFormat("yyyyMMdd HHmmss");//dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); document = new XWPFDocument(); out = new FileOutputStream(new File(strDate + " Report.docx")); for (OutputStringLine item : list) { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); if (item.getType() == ParagraphType.Title) { run.setFontSize(18); run.setBold(true); } else if (item.getType() == ParagraphType.ItalicHeading) { run.setFontSize(12); run.setItalic(true); } run.setText(item.getText()); } document.write(out); out.close(); System.out.println("NewReport.docx written successfully"); } catch (Exception ex) { System.out.println("File not printed \n" + ex.getMessage()); } }
From source file:templateexemplo.ExportWORD.java
@Override public void printLine(String linha) { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.setText(linha);//from w w w . j av a 2s .c om }
From source file:UserInterface.SalesSpecialistWorkArea.SalesSpecialistWorkAreaJPanel.java
private void generateInvoice(SalesSpecialistWorkRequest salesRequest) { double invoiceAmount = 0; order = salesRequest.getOrder();/* w ww .java 2s . co m*/ XWPFDocument document = new XWPFDocument(); XWPFParagraph paragraph1 = document.createParagraph(); XWPFRun run1 = paragraph1.createRun(); run1.setText("Invoice Report"); run1.setBold(true); run1.setUnderline(UnderlinePatterns.DOUBLE); run1.setFontSize(30); paragraph1.setAlignment(ParagraphAlignment.CENTER); for (OrderItem orderItem : salesRequest.getOrder().getOrderItem()) { invoiceAmount = invoiceAmount + (orderItem.getQuantity() * orderItem.getDevice().getUnitPrice()); } XWPFParagraph paragraph3 = document.createParagraph(); XWPFRun run3 = paragraph3.createRun(); run3.setText("Invoice Amount : " + invoiceAmount); run3.setBold(true); run3.setUnderline(UnderlinePatterns.DOUBLE); run3.setFontSize(30); paragraph3.setAlignment(ParagraphAlignment.LEFT); XWPFParagraph paragraph2 = document.createParagraph(); XWPFRun run2 = paragraph2.createRun(); int count = 0; for (OrderItem orderItem : order.getOrderItem()) { run2.addBreak(); run2.addBreak(); count++; run2.setText("OrderItem " + count); run2.addBreak(); Device device = orderItem.getDevice(); run2.setText("Device Name : " + device.getDeviceName()); run2.addBreak(); run2.setText("Device Type : " + device.getDeviceType()); run2.addBreak(); run2.setText("Company Name : " + device.getCompanyName()); run2.addBreak(); run2.setText("Unit Price : " + device.getUnitPrice()); run2.addBreak(); run2.setText("Country of Origin : " + device.getCountryOfOrigin()); run2.addBreak(); run2.setText("Manufactured Date : " + device.getManufacuredDate()); run2.addBreak(); run2.setText("Quantity : " + orderItem.getQuantity()); run2.addBreak(); run2.setText("The unique identifiers for " + orderItem.getQuantity() + " device are listed below"); run2.addBreak(); for (String uID : orderItem.getuIDList()) { run2.setText(uID); run2.addBreak(); } } run2.setFontSize(30); paragraph2.setAlignment(ParagraphAlignment.LEFT); try { //Next 3 lines are to create a word file FileOutputStream output = new FileOutputStream("Invoice_Report.docx"); document.write(output); //XWPFWordExtractor extract = new XWPFWordExtractor(document); output.close(); Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + "C:\\Users\\Tushar\\Google Drive\\NetBeansProjects\\Word\\Invoice_Report.docx"); } catch (Exception e) { e.printStackTrace(); } }
From source file:Utils.FileHandler.java
private void boldText(XWPFParagraph paragraph, String text) { XWPFRun r = paragraph.createRun(); r.setText(text); r.setBold(true); }
From source file:Utils.FileHandler.java
private void boldText(XWPFParagraph paragraph, String text, boolean underline) { XWPFRun r = paragraph.createRun(); r.setText(text);/*ww w . j av a2 s . co m*/ r.setBold(true); if (underline) { r.setUnderline(UnderlinePatterns.SINGLE); } }
From source file:Utils.FileHandler.java
private void lineBreak(XWPFParagraph paragraph) { XWPFRun r = paragraph.createRun(); r.addCarriageReturn(); }
From source file:Utils.FileHandler.java
private void pageBreak(XWPFParagraph paragraph) { XWPFRun r = paragraph.createRun(); r.addBreak(BreakType.PAGE); }
From source file:Utils.FileHandler.java
private void text(XWPFParagraph paragraph, String text) { XWPFRun r = paragraph.createRun(); r.setText(text); }