List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun setFontSize
@Override public void setFontSize(int size)
From source file:com.simplexwork.mysql.tools.utils.DocumentUtils.java
License:Apache License
/** * ??word/*w w w . j a v a 2s .co m*/ * * @param tablesMap * @throws Exception */ public static void productDatabaseDoc(Map<String, TableInfo> tablesMap) throws Exception { XWPFDocument xwpfDocument = new XWPFDocument(); for (Entry<String, TableInfo> entry : tablesMap.entrySet()) { TableInfo tableInfo = entry.getValue(); XWPFParagraph xwpfParagraph = xwpfDocument.createParagraph(); XWPFRun xwpfRun = xwpfParagraph.createRun(); xwpfRun.setText(tableInfo.getTableName() + "(" + tableInfo.getTableComment() + ")"); xwpfRun.setFontSize(18); xwpfRun.setTextPosition(10); XWPFTable xwpfTable = xwpfDocument.createTable(tableInfo.getColumns().size() + 1, 6); int i = 0; xwpfTable.getRow(i).getCell(0).setText("??"); xwpfTable.getRow(i).getCell(1).setText(""); xwpfTable.getRow(i).getCell(2).setText(""); xwpfTable.getRow(i).getCell(3).setText(""); xwpfTable.getRow(i).getCell(4).setText(""); xwpfTable.getRow(i).getCell(5).setText("?"); for (Column column : tableInfo.getColumns()) { int j = 0; i++; xwpfTable.getRow(i).getCell(j++).setText(column.getName()); xwpfTable.getRow(i).getCell(j++).setText(column.getType()); xwpfTable.getRow(i).getCell(j++).setText(column.isKey() ? "" : ""); xwpfTable.getRow(i).getCell(j++).setText(column.isNullable() ? "?" : ""); xwpfTable.getRow(i).getCell(j++).setText(column.getComment()); xwpfTable.getRow(i).getCell(j++).setText(column.getExtra()); } } File file = new File(generatedPath); if (!file.exists()) { file.mkdirs(); } FileOutputStream fos = new FileOutputStream(generatedPath + "database.docx"); xwpfDocument.write(fos); fos.close(); }
From source file:csv2docxconverter.DocumentGenerator.java
/** * Generate DocX element from list of the rows containing account information * @param columnNames a list of columns for data parsing * @param contents list of data rows for parsing * @return an XWPFDocument representing a DocX file *///from w w w. ja v a 2 s. co m public XWPFDocument generateDocx(String[] columnNames, List contents) { XWPFDocument document = new XWPFDocument(); // create title XWPFParagraph title = document.createParagraph(); title.setAlignment(ParagraphAlignment.CENTER); XWPFRun titleRun = title.createRun(); titleRun.setText("G SUITE created accounts"); titleRun.setFontSize(18); for (int k = 0; k < contents.size(); k++) { List tableContent = (List) contents.get(k); // create title title = document.createParagraph(); title.setAlignment(ParagraphAlignment.CENTER); titleRun = title.createRun(); titleRun.setText("Table " + (k + 1)); titleRun.setFontSize(18); // create account table XWPFTable table = document.createTable(); // set "justified" alignment table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(10000)); //create header for table setHeader(table, columnNames); // if account list is empty if (tableContent == null || tableContent.size() == 0) { // add empty row to the table XWPFTableRow emptyRow = table.createRow(); } else { String[] headerRow = null; // create rows in table for (int i = 0; i < tableContent.size(); i++) { if (i == 0) { headerRow = (String[]) tableContent.get(i); continue; } String[] csvRow = (String[]) tableContent.get(i); XWPFTableRow row = table.createRow(); //create cells in a row for (int j = 0; j < columnNames.length; j++) { int number = getColumnNumber(columnNames[j], headerRow); XWPFTableCell cell = row.getCell(j); if (cell != null) { XWPFRun run = setBodyCell(cell); if (number >= 0 && number < csvRow.length) { run.setText(csvRow[number]); } } } } } } return document; }
From source file:de.knowwe.include.export.InlineDefinitionExporter.java
License:Open Source License
@Override public void export(Section<InlineDefinitionType> section, DocumentBuilder manager) throws ExportException { ExportUtils.addRequiredSpace(manager); String refID = HeaderExporter.getCrossReferenceID(section); XWPFRun run = HeaderExporter.createCrossReferenceRun(refID, manager); run.setColor("606060"); run.setFontSize(7); run.setText("("); run.setText(section.get().getHeadText(section)); run.setText(": "); manager.export(section.get().getDataSection(section)); run = manager.getParagraph().createRun(); run.setColor("606060"); run.setFontSize(7);/*w ww . j a v a 2 s .c o m*/ run.setText(")"); run = manager.getParagraph().createRun(); run.setText(" "); }
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 . j av a 2 s . c o m 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:eremeykin.pete.reports.ui.ReportAction.java
@Override public void actionPerformed(ActionEvent e) { resultChanged(null);/*from ww w . jav 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:fr.opensagres.poi.xwpf.converter.xhtml.internal.XHTMLMapper.java
License:Open Source License
@Override protected void visitStyleText(XWPFRun run, String text) throws Exception { if (run.getFontFamily() == null) { run.setFontFamily(getStylesDocument().getFontFamilyAscii(run)); }//from w w w . j a v a 2 s. co m if (run.getFontSize() <= 0) { run.setFontSize(getStylesDocument().getFontSize(run).intValue()); } CTRPr rPr = run.getCTR().getRPr(); // 1) create attributes // 1.1) Create "class" attributes. AttributesImpl runAttributes = createClassAttribute(currentParagraph.getStyleID()); // 1.2) Create "style" attributes. CSSStyle cssStyle = getStylesDocument().createCSSStyle(rPr); if (cssStyle != null) { Color color = RunTextHighlightingValueProvider.INSTANCE.getValue(rPr, getStylesDocument()); if (color != null) cssStyle.addProperty(CSSStylePropertyConstants.BACKGROUND_COLOR, StringUtils.toHexString(color)); if (Boolean.TRUE.equals(RunFontStyleStrikeValueProvider.INSTANCE.getValue(rPr, getStylesDocument())) || rPr.getDstrike() != null) cssStyle.addProperty("text-decoration", "line-through"); if (rPr.getVertAlign() != null) { int align = rPr.getVertAlign().getVal().intValue(); if (STVerticalAlignRun.INT_SUPERSCRIPT == align) { cssStyle.addProperty("vertical-align", "super"); } else if (STVerticalAlignRun.INT_SUBSCRIPT == align) { cssStyle.addProperty("vertical-align", "sub"); } } } runAttributes = createStyleAttribute(cssStyle, runAttributes); if (runAttributes != null) { startElement(SPAN_ELEMENT, runAttributes); } if (StringUtils.isNotEmpty(text)) { // Escape with HTML characters characters(StringEscapeUtils.escapeHtml(text)); } if (runAttributes != null) { endElement(SPAN_ELEMENT); } }
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 a 2 s . c o m 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 {/* w ww .j a va2s .com*/ // 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 {// w ww . ja v a2 s.com // 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 ww . j a v a 2 s .co m 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); } }