Java Code Examples for org.docx4j.wml.ObjectFactory#createText()
The following examples show how to use
org.docx4j.wml.ObjectFactory#createText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Docx4j_工具类_S3_Test.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * @Description: 添加图片到段落 */ public void addImageToPara(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, P paragraph, String filePath, String content, RPr rpr, String altText, int id1, int id2) throws Exception { R run = factory.createR(); if (content != null) { Text text = factory.createText(); text.setValue(content); text.setSpace("preserve"); run.setRPr(rpr); run.getContent().add(text); } InputStream is = new FileInputStream(filePath); byte[] bytes = IOUtils.toByteArray(is); BinaryPartAbstractImage imagePart = BinaryPartAbstractImage .createImagePart(wordMLPackage, bytes); Inline inline = imagePart.createImageInline(filePath, altText, id1, id2, false); Drawing drawing = factory.createDrawing(); drawing.getAnchorOrInline().add(inline); run.getContent().add(drawing); paragraph.getContent().add(run); }
Example 2
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception { Ftr ftr = factory.createFtr(); P footerP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); footerP.getContent().add(run); PPr pPr = footerP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); footerP.setPPr(pPr); ftr.getContent().add(footerP); return ftr; }
Example 3
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception { Hdr hdr = factory.createHdr(); P headP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); headP.getContent().add(run); PPr pPr = headP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); headP.setPPr(pPr); hdr.getContent().add(headP); return hdr; }
Example 4
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception { Ftr ftr = factory.createFtr(); P footerP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); footerP.getContent().add(run); PPr pPr = footerP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); footerP.setPPr(pPr); ftr.getContent().add(footerP); return ftr; }
Example 5
Source File: Docx4j_创建批注_S3_Test.java From docx4j-template with Apache License 2.0 | 6 votes |
public Comments.Comment createComment(ObjectFactory factory, BigInteger commentId, String author, Date date, String commentContent, RPr commentRPr) throws Exception { Comments.Comment comment = factory.createCommentsComment(); comment.setId(commentId); if (author != null) { comment.setAuthor(author); } if (date != null) { comment.setDate(toXMLCalendar(date)); } P commentP = factory.createP(); comment.getEGBlockLevelElts().add(commentP); R commentR = factory.createR(); commentP.getContent().add(commentR); Text commentText = factory.createText(); commentR.getContent().add(commentText); commentR.setRPr(commentRPr); commentText.setValue(commentContent); return comment; }
Example 6
Source File: Docx4j_创建批注_S3_Test.java From docx4j-template with Apache License 2.0 | 6 votes |
public void createCommentRound(ObjectFactory factory, P p, String pContent, String commentContent, RPr fontRPr, RPr commentRPr, BigInteger commentId, Comments comments) throws Exception { CommentRangeStart startComment = factory.createCommentRangeStart(); startComment.setId(commentId); p.getContent().add(startComment); R run = factory.createR(); Text txt = factory.createText(); txt.setValue(pContent); run.getContent().add(txt); run.setRPr(fontRPr); p.getContent().add(run); CommentRangeEnd endComment = factory.createCommentRangeEnd(); endComment.setId(commentId); p.getContent().add(endComment); Comment commentOne = createComment(factory, commentId, "系统管理员", new Date(), commentContent, commentRPr); comments.getComment().add(commentOne); p.getContent().add(createRunCommentReference(factory, commentId)); }
Example 7
Source File: WmlElementUtils.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * @Description: 添加图片到段落 */ public static void addImageToPara(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, P paragraph, String filePath, String content, RPr rpr, String altText, int id1, int id2) throws Exception { R run = factory.createR(); if (content != null) { Text text = factory.createText(); text.setValue(content); text.setSpace("preserve"); run.setRPr(rpr); run.getContent().add(text); } InputStream is = new FileInputStream(filePath); byte[] bytes = IOUtils.toByteArray(is); BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes); Inline inline = imagePart.createImageInline(filePath, altText, id1, id2, false); Drawing drawing = factory.createDrawing(); drawing.getAnchorOrInline().add(inline); run.getContent().add(drawing); paragraph.getContent().add(run); }
Example 8
Source File: Docx4j_创建批注_S3_Test.java From docx4j-template with Apache License 2.0 | 5 votes |
public void createCommentEnd(ObjectFactory factory, P p, String pContent, String commentContent, RPr fontRPr, RPr commentRPr, BigInteger commentId, Comments comments) throws Exception{ Text txt = factory.createText(); txt.setValue(pContent); R run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); p.getContent().add(run); Comment commentOne = createComment(factory, commentId, "系统管理员",new Date(), commentContent, commentRPr); comments.getComment().add(commentOne); p.getContent().add(createRunCommentReference(factory, commentId)); }
Example 9
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) { Tc tableCell = factory.createTc(); P p = factory.createP(); setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); Text t = factory.createText(); t.setValue(content); R run = factory.createR(); // 设置表格内容字体样式 run.setRPr(rpr); TcPr tcPr = tableCell.getTcPr(); if (tcPr == null) { tcPr = factory.createTcPr(); } CTVerticalJc valign = factory.createCTVerticalJc(); valign.setVal(STVerticalJc.CENTER); tcPr.setVAlign(valign); run.getContent().add(t); p.getContent().add(run); tableCell.getContent().add(p); if (hasBgColor) { CTShd shd = tcPr.getShd(); if (shd == null) { shd = factory.createCTShd(); } shd.setColor("auto"); shd.setFill(backgroudColor); tcPr.setShd(shd); } tableCell.setTcPr(tcPr); tableRow.getContent().add(tableCell); }
Example 10
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public P createImageParagraph(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, P p, String fileName, String content, byte[] bytes, JcEnumeration jcEnumeration) throws Exception { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage .createImagePart(wordMLPackage, bytes); Inline inline = imagePart.createImageInline(fileName, "这是图片", 1, 2, false); Text text = factory.createText(); text.setValue(content); text.setSpace("preserve"); R run = factory.createR(); p.getContent().add(run); run.getContent().add(text); Drawing drawing = factory.createDrawing(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); p.setPPr(pPr); setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); return p; }
Example 11
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception { Hdr hdr = factory.createHdr(); P headP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); headP.getContent().add(run); PPr pPr = headP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); PBdr pBdr=pPr.getPBdr(); if(pBdr==null){ pBdr=factory.createPPrBasePBdr(); } CTBorder value=new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger("3")); pBdr.setBetween(value); pPr.setPBdr(pBdr); headP.setPPr(pPr); setParagraphSpacing(factory, headP, jcEnumeration, "0", "0"); hdr.getContent().add(headP); hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, jcEnumeration)); return hdr; }
Example 12
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public P createImageParagraph(WordprocessingMLPackage wordMLPackage, ObjectFactory factory,P p,String fileName, String content,byte[] bytes, JcEnumeration jcEnumeration) throws Exception { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage .createImagePart(wordMLPackage, bytes); Inline inline = imagePart.createImageInline(fileName, "这是图片", 1, 2, false); Text text = factory.createText(); text.setValue(content); text.setSpace("preserve"); R run = factory.createR(); p.getContent().add(run); run.getContent().add(text); Drawing drawing = factory.createDrawing(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); PPr pPr = p.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); p.setPPr(pPr); setParagraphSpacing(factory, p, jcEnumeration, "0", "0"); return p; }
Example 13
Source File: Docx4j_创建表格_S5_Test.java From docx4j-template with Apache License 2.0 | 5 votes |
public void addCellStyle(ObjectFactory factory, Tc tableCell, String content, Docx4jStyle_S3 style) { if (style != null) { P paragraph = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); paragraph.getContent().add(run); setHorizontalAlignment(paragraph, style.getHorizAlignment()); RPr runProperties = factory.createRPr(); if (style.isBold()) { addBoldStyle(runProperties); } if (style.isItalic()) { addItalicStyle(runProperties); } if (style.isUnderline()) { addUnderlineStyle(runProperties); } setFontSize(runProperties, style.getFontSize()); setFontColor(runProperties, style.getFontColor()); setFontFamily(runProperties, style.getCnFontFamily(),style.getEnFontFamily()); setCellMargins(tableCell, style.getTop(), style.getRight(), style.getBottom(), style.getLeft()); setCellColor(tableCell, style.getBackground()); setVerticalAlignment(tableCell, style.getVerticalAlignment()); setCellBorders(tableCell, style.isBorderTop(), style.isBorderRight(), style.isBorderBottom(), style.isBorderLeft()); run.setRPr(runProperties); tableCell.getContent().add(paragraph); } }
Example 14
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) { Tc tableCell = factory.createTc(); P p = factory.createP(); setParagraphAlign(factory, p, jcEnumeration); Text t = factory.createText(); t.setValue(content); R run = factory.createR(); // 设置表格内容字体样式 run.setRPr(rpr); run.getContent().add(t); p.getContent().add(run); tableCell.getContent().add(p); if (hasBgColor) { TcPr tcPr = tableCell.getTcPr(); if (tcPr == null) { tcPr = factory.createTcPr(); } CTShd shd = tcPr.getShd(); if (shd == null) { shd = factory.createCTShd(); } shd.setColor("auto"); shd.setFill(backgroudColor); tcPr.setShd(shd); tableCell.setTcPr(tcPr); } tableRow.getContent().add(tableCell); }
Example 15
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) { Tc tableCell = factory.createTc(); P p = factory.createP(); setParagraphAlign(factory, p, jcEnumeration); Text t = factory.createText(); t.setValue(content); R run = factory.createR(); // 设置表格内容字体样式 run.setRPr(rpr); TcPr tcPr = tableCell.getTcPr(); if (tcPr == null) { tcPr = factory.createTcPr(); } CTVerticalJc valign = factory.createCTVerticalJc(); valign.setVal(STVerticalJc.CENTER); tcPr.setVAlign(valign); run.getContent().add(t); p.getContent().add(run); PPr ppr=p.getPPr(); if(ppr==null){ ppr=factory.createPPr(); } //设置段后距离 Spacing spacing=new Spacing(); spacing.setAfter(new BigInteger("0")); spacing.setLineRule(STLineSpacingRule.AUTO); ppr.setSpacing(spacing); p.setPPr(ppr); tableCell.getContent().add(p); if (hasBgColor) { CTShd shd = tcPr.getShd(); if (shd == null) { shd = factory.createCTShd(); } shd.setColor("auto"); shd.setFill(backgroudColor); tcPr.setShd(shd); tableCell.setTcPr(tcPr); } tableRow.getContent().add(tableCell); }
Example 16
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { Ftr ftr = factory.createFtr(); P footerP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); footerP.getContent().add(run); PPr pPr = footerP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); footerP.setPPr(pPr); setParagraphSpacing(factory, footerP, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); if (isUnderLine) { PBdr pBdr = pPr.getPBdr(); if (pBdr == null) { pBdr = factory.createPPrBasePBdr(); } CTBorder value = new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger(underLineSz)); pBdr.setBetween(value); pPr.setPBdr(pBdr); footerP.setPPr(pPr); } ftr.getContent().add(footerP); if (isUnderLine) { ftr.getContent().add( createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration)); } return ftr; }
Example 17
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 4 votes |
public void addParagraphTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { RPr titleRPr = getRPr(factory, "黑体", "000000", "28", STHint.EAST_ASIA, true, false, false, false); RPr boldRPr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false); RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA, false, false, false, false); P paragraph = factory.createP(); setParagraphAlign(factory, paragraph, JcEnumeration.CENTER); Text txt = factory.createText(); txt.setValue("七年级上册Unit2 This is just a test. sectionA测试卷答题卡"); R run = factory.createR(); run.getContent().add(txt); run.setRPr(titleRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); setParagraphAlign(factory, paragraph, JcEnumeration.CENTER); txt = factory.createText(); txt.setValue("班级:________ 姓名:________"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("一、单选题"); run = factory.createR(); run.getContent().add(txt); run.setRPr(boldRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("1.下列有关仪器用途的说法错误的是( )"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("A.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("B.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("C.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("D.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); }
Example 18
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { Hdr hdr = factory.createHdr(); P headP = factory.createP(); Text text = factory.createText(); text.setValue(content); R run = factory.createR(); run.getContent().add(text); headP.getContent().add(run); PPr pPr = headP.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); if (isUnderLine) { PBdr pBdr = pPr.getPBdr(); if (pBdr == null) { pBdr = factory.createPPrBasePBdr(); } CTBorder value = new CTBorder(); value.setVal(STBorder.SINGLE); value.setColor("000000"); value.setSpace(new BigInteger("0")); value.setSz(new BigInteger(underLineSz)); pBdr.setBetween(value); pPr.setPBdr(pBdr); headP.setPPr(pPr); } setParagraphSpacing(factory, headP, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); hdr.getContent().add(headP); if (isUnderLine) { hdr.getContent().add( createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration)); } return hdr; }