List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument XWPFDocument
public XWPFDocument()
From source file:library.Form_Library.java
private void btPrintReaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPrintReaderActionPerformed try {/* ww w.ja v a2 s . 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
public void PrintBook(BooksFrame booksFrame, Book book, Account _account) { try {/*from w w w. j a v a 2s.c om*/ XWPFDocument document = new XWPFDocument(); File file = new File("Sch " + book.getIdCode() + ".doc"); if (file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); XWPFParagraph paragraph = document.createParagraph(); paragraph.setAlignment(ParagraphAlignment.CENTER); XWPFRun run; BookViewModel bookView = new BookViewModel(book); ///////////////// run = createFieldRun(paragraph, "THNG TIN S?CH"); run.setFontSize(24); paragraph = createPrintInformation(document, _account); paragraph = createBookProductInformation(document, bookView); paragraph = createBookInformation(document, bookView); document.write(out); out.close(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(file); } JOptionPane .showMessageDialog(booksFrame, "Xut file " + file.getName() + " thnh cng" + '\n' + "Ti v tr: " + file.getAbsolutePath(), "In thng tin Sch", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(booksFrame, "Xut file tht bi." + '\n' + "Vui lng ng ca s ang s dng file", "In thng tin Sch", JOptionPane.WARNING_MESSAGE); } }
From source file:MainPackage.Controllers.OrderController.java
public void Print(Frame frame, Orders order, Account _account) { try {/*from w w w.ja va2s.c om*/ XWPFDocument document = new XWPFDocument(); File file = new File("Ha n " + order.getIdCode() + ".doc"); if (file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); XWPFParagraph paragraph = document.createParagraph(); paragraph.setAlignment(ParagraphAlignment.CENTER); XWPFRun run; // BookViewModel bookView = new BookViewModel(book); ///////////////// run = createFieldRun(paragraph, "CHI TIT HA ?N"); run.setFontSize(24); paragraph = createPrintInformation(document, _account); paragraph = createBookProductInformation(document, order); paragraph = createBookInformation(document, order); //create table XWPFTable table = document.createTable(); setTableAlignment(table, STJc.CENTER); table.setCellMargins(50, 50, 50, 50); table.setInsideHBorder(XWPFTable.XWPFBorderType.SINGLE, 10, 10, ""); table.setInsideVBorder(XWPFTable.XWPFBorderType.NONE, 20, 20, ""); //create first row XWPFTableRow row = table.getRow(0); row.setHeight(40); row.getCell(0).setText("STT"); row.addNewTableCell().setText("M Sn phm"); row.addNewTableCell().setText("Tn Sn phm"); row.addNewTableCell().setText("?n v"); row.addNewTableCell().setText("S lng"); row.addNewTableCell().setText("Gi ti?n"); row.addNewTableCell().setText("Thnh ti?n"); List<OrderLine> list = (List<OrderLine>) order.getOrderLineCollection(); for (int i = 0; i < list.size(); i++) { OrderLine line = list.get(i); row = table.createRow(); row.getCell(0).setText((i + 1) + ""); row.getCell(1).setText(line.getProductId().getIdCode()); row.getCell(2).setText(line.getProductId().getName()); row.getCell(3).setText("Quyn "); row.getCell(4).setText(line.getQuantity() + " "); row.getCell(5).setText(IntToVND(line.getUnitPrice()) + " "); row.getCell(6).setText(IntToVND(line.getTotalPrice()) + " "); } document.write(out); out.close(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(file); } JOptionPane .showMessageDialog(frame, "Xut file " + file.getName() + " thnh cng" + '\n' + "Ti v tr: " + file.getAbsolutePath(), "In thng tin Ha n", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(frame, "Xut file tht bi." + '\n' + "Vui lng ng ca s ang s dng file", "In thng tin Ha n", JOptionPane.WARNING_MESSAGE); } }
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 w ww. j ava 2 s . c o 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();/*from w w w. ja va 2 s .c om*/ r4.setTextPosition(20); 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:modificarcabeceradocs.appModificacionDOCs.java
private void modificarDOCs(File pathsDocumento) throws FileNotFoundException, IOException { XWPFDocument doc = new XWPFDocument(); XWPFHeaderFooterPolicy policy = doc.getHeaderFooterPolicy(); if (policy.getDefaultHeader() == null && policy.getFirstPageHeader() == null && policy.getDefaultFooter() == null) { // Need to create some new headers // The easy way, gives a single empty paragraph XWPFHeader headerD = policy.createHeader(policy.DEFAULT); //headerD.getParagraphs().createRun().setText("Hello Header World!"); headerD.getParagraphArray(0).createRun().setText("AAAAAAAAAAAAA"); // Or the full control way CTP ctP1 = CTP.Factory.newInstance(); CTR ctR1 = ctP1.addNewR();//w w w.ja v a 2 s .co m CTText t = ctR1.addNewT(); t.setStringValue("Paragraph in header"); XWPFParagraph p1 = new XWPFParagraph(ctP1, doc); XWPFParagraph[] pars = new XWPFParagraph[1]; pars[0] = p1; policy.createHeader(policy.FIRST, pars); doc.write(new FileOutputStream(new File("prueba.docx"))); System.out.println("Cabecera terminada"); } else { // Already has a header, change it } }
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 ww w. ja va 2s .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.Word.java
License:MIT License
/** * //from w ww.j a v a 2 s. c om */ private Word() { this.path = Locator.temporaryFile().asJavaPath(); this.calculated = new XWPFDocument(); CTSectPr sect = calculated.getDocument().getBody().getSectPr(); section.getSize(sect); section.getMargin(sect); }
From source file:oop.nhom5.de3.model.IOFileWord.java
public static boolean writeWord(String text, String fileName) { //Blank Document XWPFDocument document = new XWPFDocument(); //Write the Document in file system try {/*from www .j a v a 2 s . c om*/ FileOutputStream out = new FileOutputStream(new File(fileName)); String[] lines = text.split("\n"); //create Paragraph for (String line : lines) { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.setText(line); } document.write(out); out.close(); return true; } catch (IOException | HeadlessException e) { e.printStackTrace(); } return false; }
From source file:org.cgiar.ccafs.marlo.action.summaries.AnualReportPOISummaryAction.java
License:Open Source License
public AnualReportPOISummaryAction(APConfig config, GlobalUnitManager crpManager, PhaseManager phaseManager, PowbExpenditureAreasManager powbExpenditureAreasManager, ReportSynthesisManager reportSynthesisManager, ReportSynthesisCrpProgressTargetManager reportSynthesisCrpProgressTargetManager, RepIndSynthesisIndicatorManager repIndSynthesisIndicatorManager, ProjectManager projectManager, ReportSynthesisExternalPartnershipManager reportSynthesisExternalPartnershipManager, ReportSynthesisMeliaManager reportSynthesisMeliaManager, ReportSynthesisCrossCgiarCollaborationManager reportSynthesisCrossCgiarCollaborationManager, ReportSynthesisFlagshipProgressManager reportSynthesisFlagshipProgressManager, ReportSynthesisFinancialSummaryBudgetManager reportSynthesisFinancialSummaryBudgetManager, ReportSynthesisFlagshipProgressMilestoneManager reportSynthesisFlagshipProgressMilestoneManager, ReportSynthesisCrossCuttingDimensionManager reportSynthesisCrossCuttingDimensionManager, ReportSynthesisCrpProgressManager reportSynthesisCrpProgressManager, CrpProgramManager crpProgramManager) { super(config, crpManager, phaseManager, projectManager); document = new XWPFDocument(); poiSummary = new POISummary(); currencyFormat = NumberFormat.getCurrencyInstance(); percentageFormat = new DecimalFormat("##.##%"); this.powbExpenditureAreasManager = powbExpenditureAreasManager; this.reportSynthesisManager = reportSynthesisManager; this.reportSynthesisCrpProgressTargetManager = reportSynthesisCrpProgressTargetManager; this.repIndSynthesisIndicatorManager = repIndSynthesisIndicatorManager; this.reportSynthesisExternalPartnershipManager = reportSynthesisExternalPartnershipManager; this.reportSynthesisMeliaManager = reportSynthesisMeliaManager; this.reportSynthesisCrossCgiarCollaborationManager = reportSynthesisCrossCgiarCollaborationManager; this.reportSynthesisFlagshipProgressManager = reportSynthesisFlagshipProgressManager; this.reportSynthesisFinancialSummaryBudgetManager = reportSynthesisFinancialSummaryBudgetManager; this.reportSynthesisFlagshipProgressMilestoneManager = reportSynthesisFlagshipProgressMilestoneManager; this.reportSynthesisCrossCuttingDimensionManager = reportSynthesisCrossCuttingDimensionManager; this.reportSynthesisCrpProgressManager = reportSynthesisCrpProgressManager; this.crpProgramManager = crpProgramManager; }