List of usage examples for org.apache.poi.xwpf.usermodel VerticalAlign SUBSCRIPT
VerticalAlign SUBSCRIPT
To view the source code for org.apache.poi.xwpf.usermodel VerticalAlign SUBSCRIPT.
Click Source Link
From source file:com.min.word.core.MakeWordFileTest.java
License:Apache License
public static void main(String[] args) throws Exception { String fileName = "test.docx"; System.out.println("---------- Word Create Start ------------"); // word ? ?/*from w w w . jav a2s . com*/ XWPFDocument document = new XWPFDocument(); FileOutputStream out = new FileOutputStream(new File(fileName)); System.out.println("---------- Create Blank Success ------------"); //Paragraph ? XWPFParagraph paragraph = document.createParagraph(); System.out.println("---------- Create Paragraph Success ------------"); //border ? paragraph.setBorderBottom(Borders.BASIC_BLACK_DASHES); paragraph.setBorderLeft(Borders.BASIC_BLACK_DASHES); paragraph.setBorderRight(Borders.BASIC_BLACK_DASHES); paragraph.setBorderTop(Borders.BASIC_BLACK_DASHES); System.out.println("---------- Create Border Success ------------"); XWPFRun run = paragraph.createRun(); run.setText("At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming Languages."); System.out.println("---------- Text Write to File ------------"); //Table ? XWPFTable table = document.createTable(); //row XWPFTableRow rowOne = table.getRow(0); rowOne.getCell(0).setText("Col One, Row One"); rowOne.addNewTableCell().setText("Col Tow, Row One"); rowOne.addNewTableCell().setText("Col Three, Row One"); //row XWPFTableRow rowTow = table.createRow(); rowTow.getCell(0).setText("Col One, Row Tow"); rowTow.getCell(1).setText("Col Tow, Row Tow"); rowTow.getCell(2).setText("Col Three, Row Tow"); //row XWPFTableRow rowThree = table.createRow(); rowThree.getCell(0).setText("Col One, Row Three"); rowThree.getCell(1).setText("Col Tow, Row Three"); rowThree.getCell(2).setText("Col Three, Row Three"); System.out.println("---------- Create Table Success ------------"); //Add Image XWPFParagraph imageParagraph = document.createParagraph(); XWPFRun imageRun = imageParagraph.createRun(); imageRun.addPicture(new FileInputStream("test.png"), XWPFDocument.PICTURE_TYPE_PNG, "test.png", Units.toEMU(300), Units.toEMU(300)); System.out.println("---------- Create Image Success ------------"); //Hyperlink XWPFParagraph hyperlink = document.createParagraph(); String id = hyperlink.getDocument().getPackagePart() .addExternalRelationship("http://niee.kr", XWPFRelation.HYPERLINK.getRelation()).getId(); CTR ctr = CTR.Factory.newInstance(); CTHyperlink ctHyperlink = hyperlink.getCTP().addNewHyperlink(); ctHyperlink.setId(id); CTText ctText = CTText.Factory.newInstance(); ctText.setStringValue("Hyper-Link TEST"); ctr.setTArray(new CTText[] { ctText }); // ???? ? CTColor color = CTColor.Factory.newInstance(); color.setVal("0000FF"); CTRPr ctrPr = ctr.addNewRPr(); ctrPr.setColor(color); ctrPr.addNewU().setVal(STUnderline.SINGLE); // CTFonts fonts = ctrPr.isSetRFonts() ? ctrPr.getRFonts() : ctrPr.addNewRFonts(); fonts.setAscii("?? "); fonts.setEastAsia("?? "); fonts.setHAnsi("?? "); // ? CTHpsMeasure sz = ctrPr.isSetSz() ? ctrPr.getSz() : ctrPr.addNewSz(); sz.setVal(new BigInteger("24")); ctHyperlink.setRArray(new CTR[] { ctr }); hyperlink.setAlignment(ParagraphAlignment.LEFT); hyperlink.setVerticalAlignment(TextAlignment.CENTER); System.out.println("---------- Create Hyperlink Success ------------"); //Font style XWPFParagraph fontStyle = document.createParagraph(); //set Bold an Italic XWPFRun boldAnItalic = fontStyle.createRun(); boldAnItalic.setBold(true); boldAnItalic.setItalic(true); boldAnItalic.setText("Bold an Italic"); boldAnItalic.addBreak(); //set Text Position XWPFRun textPosition = fontStyle.createRun(); textPosition.setText("Set Text Position"); textPosition.setTextPosition(100); //Set Strike through and font Size and Subscript XWPFRun otherStyle = fontStyle.createRun(); otherStyle.setStrike(true); otherStyle.setFontSize(20); otherStyle.setSubscript(VerticalAlign.SUBSCRIPT); otherStyle.setText(" Set Strike through and font Size and Subscript"); System.out.println("---------- Set Font Style ------------"); //Set Alignment Paragraph XWPFParagraph alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.RIGHT); XWPFRun alignRight = alignment.createRun(); alignRight.setText( "At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming " + "Languages."); //Alignment to Center alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.CENTER); XWPFRun alignCenter = alignment.createRun(); alignCenter.setText("The endeavour started by Mohtashim, an AMU " + "alumni, who is the founder and the managing director " + "of Tutorials Point (I) Pvt. Ltd. He came up with the " + "website tutorialspoint.com in year 2006 with the help" + "of handpicked freelancers, with an array of tutorials" + " for computer programming languages. "); System.out.println("---------- Set Alignment ------------"); //word ? document.write(out); out.close(); System.out.println("---------- Save File Name : " + fileName + " ------------"); System.out.println("---------- Word Create End ------------"); }
From source file:org.articleEditor.insertContent.DocumentUpdater1.java
License:Apache License
public void applyAttributes(XWPFRun run, AttributeSet attributes) { Enumeration attributeNames = attributes.getAttributeNames(); while (attributeNames.hasMoreElements()) { Object attributeName = attributeNames.nextElement(); Object attributeValue = attributes.getAttribute(attributeName); if (attributeName == Bold) { run.setBold((Boolean) attributeValue); } else if (attributeName == Italic) { run.setItalic((Boolean) attributeValue); } else if (attributeName == Underline) { run.setUnderline((Boolean) attributeValue ? UnderlinePatterns.SINGLE : UnderlinePatterns.NONE); } else if (attributeName == FontFamily || attributeName == Family) { run.setFontFamily((String) attributeValue); } else if (attributeName == FontSize) { run.setFontSize(((Number) attributeValue).intValue()); } else if (attributeName == Foreground) { Color color = (Color) attributeValue; String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); run.setColor(rgb);/* www . j a va 2s. c o m*/ } else if (attributeName == Background) { Color color = (Color) attributeValue; String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); //run.getCTR().getRPr().setHighlight(); } else if (attributeName == Subscript) { run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUBSCRIPT : VerticalAlign.BASELINE); } else if (attributeName == Superscript) { run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUPERSCRIPT : VerticalAlign.BASELINE); } else if (attributeName == StrikeThrough) { run.setStrike((Boolean) attributeValue); } else if (attributeName == Alignment) { ParagraphAlignment alignment = documentToPOI((Integer) attributeValue); run.getParagraph().setAlignment(alignment); } } }
From source file:org.articleEditor.insertContent.POIDocxReader.java
License:Apache License
protected void processRun(XWPFRun run) throws BadLocationException { charAttrs = new SimpleAttributeSet(); if (run.getFontSize() > 0) { int size = run.getFontSize(); StyleConstants.setFontSize(charAttrs, size); }/* www . j av a 2s .com*/ StyleConstants.setBold(charAttrs, run.isBold()); StyleConstants.setItalic(charAttrs, run.isItalic()); StyleConstants.setStrikeThrough(charAttrs, run.isStrike()); boolean underlined = run.getUnderline() != UnderlinePatterns.NONE; StyleConstants.setUnderline(charAttrs, underlined); VerticalAlign verticalAlignment = run.getSubscript(); if (verticalAlignment == VerticalAlign.SUBSCRIPT) { StyleConstants.setSubscript(parAttrs, true); } else if (verticalAlignment == VerticalAlign.SUPERSCRIPT) { StyleConstants.setSuperscript(parAttrs, true); } else { StyleConstants.setSubscript(parAttrs, false); StyleConstants.setSuperscript(parAttrs, false); } if (run.getFontFamily() != null) { StyleConstants.setFontFamily(charAttrs, run.getFontFamily()); } if (run.getColor() != null) { String name = run.getColor(); if (!name.toLowerCase().equals("auto")) { Color color = Color.decode("#" + name); StyleConstants.setForeground(charAttrs, color); } } // Not working if (run.getCTR().getRPr() != null && run.getCTR().getRPr().getHighlight() != null) { STHighlightColor.Enum colorEnum = run.getCTR().getRPr().getHighlight().getVal(); Color color = decodeHighlightName(colorEnum); StyleConstants.setBackground(charAttrs, color); } for (XWPFPicture picture : run.getEmbeddedPictures()) { processPicture(picture); } String text = run.toString(); document.insertString(currentOffset, text, charAttrs); currentOffset += text.length(); }