private void addBrRunToDocFrag(List<Object> contents, RPr rPr) throws JAXBException { // Not sure whether there is ever anything of interest in the rPr, // but add it anyway org.docx4j.wml.R run = Context.getWmlObjectFactory().createR(); if (rPr!=null) { run.setRPr(rPr); } run.getRunContent().add(Context.getWmlObjectFactory().createBr()); contents.add(run); }
public void setResult(String val) { resultsSlot.getContent().clear(); StringTokenizer st = new StringTokenizer(val, "\n\r\f"); // tokenize on the newline character, the carriage-return character, and the form-feed character // our docfrag may contain several runs boolean firsttoken = true; while (st.hasMoreTokens()) { String line = (String) st.nextToken(); if (firsttoken) { firsttoken = false; } else { resultsSlot.getContent().add(Context.getWmlObjectFactory().createBr()); } org.docx4j.wml.Text text = Context.getWmlObjectFactory().createText(); resultsSlot.getContent().add(text); if (line.startsWith(" ") || line.endsWith(" ") ) { // TODO: tab character? text.setSpace("preserve"); } text.setValue(line); } }
protected void addBrRunToDocFrag(DocumentFragment docfrag, RPr rPr) throws Docx4JException { // Not sure whether there is ever anything of interest in the rPr, // but add it anyway org.docx4j.wml.R run = Context.getWmlObjectFactory().createR(); if (rPr!=null) { run.setRPr(rPr); } run.getRunContent().add(Context.getWmlObjectFactory().createBr()); Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(run); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); }
@Override public void addBreak(STBrType breakType) { // Create object for br R r = myFactory.createR(); Br br = myFactory.createBr(); if (breakType != null) br.setType(breakType); r.getContent().add(br); myRunContainer.addR(r); }
private void replaceLineBreaks(ParagraphWrapper paragraphWrapper) { Br lineBreak = Context.getWmlObjectFactory().createBr(); R run = RunUtil.create(lineBreak); while (paragraphWrapper.getText().contains(this.lineBreakPlaceholder)) { replace(paragraphWrapper, this.lineBreakPlaceholder, run); } }
private void addBrRunToDocFrag(List<Object> contents, RPr rPr) throws JAXBException { // Not sure whether there is ever anything of interest in the rPr, // but add it anyway org.docx4j.wml.R run = Context.getWmlObjectFactory().createR(); if (rPr!=null) { run.setRPr(rPr); } run.getRunContent().add(Context.getWmlObjectFactory().createBr()); contents.add(run); }
public void setResult(String val) { resultsSlot.getContent().clear(); StringTokenizer st = new StringTokenizer(val, "\n\r\f"); // tokenize on the newline character, the carriage-return character, and the form-feed character // our docfrag may contain several runs boolean firsttoken = true; while (st.hasMoreTokens()) { String line = (String) st.nextToken(); if (firsttoken) { firsttoken = false; } else { resultsSlot.getContent().add(Context.getWmlObjectFactory().createBr()); } org.docx4j.wml.Text text = Context.getWmlObjectFactory().createText(); resultsSlot.getContent().add(text); if (line.startsWith(" ") || line.endsWith(" ") ) { // TODO: tab character? text.setSpace("preserve"); } text.setValue(line); } }
protected void addBrRunToDocFrag(DocumentFragment docfrag, RPr rPr) throws Docx4JException { // Not sure whether there is ever anything of interest in the rPr, // but add it anyway org.docx4j.wml.R run = Context.getWmlObjectFactory().createR(); if (rPr!=null) { run.setRPr(rPr); } run.getRunContent().add(Context.getWmlObjectFactory().createBr()); Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(run); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); }
run.getContent().add(Context.getWmlObjectFactory().createBr());
ObjectFactory factory = Context.getWmlObjectFactory(); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .createPackage(); P spc = factory.createP(); R rspc = factory.createR(); Text t1 = factory.createText(); t1.setValue("tset"); rspc.getContent().add(t1); Br br = factory.createBr(); // this Br element is used break the current and go for next line rspc.getContent().add(br); Text t2 = factory.createText(); t2.setValue("\r\n tset2"); rspc.getContent().add(t2); spc.getContent().add(rspc); wordMLPackage.getMainDocumentPart().addObject(spc); wordMLPackage.save(new java.io.File("helloworld.docx"));
ObjectFactory factory = Context.getWmlObjectFactory(); R run = factory.createR(); Text text1 = factory.createText(); text1.setValue("asd"); run.getContent().add(text1); Br nl = factory.createBr(); run.getContent().add(nl); Text text2 = factory.createText(); text2.setValue("efg"); run.getContent().add(text2); P para = factory.createP(); para.getParagraphContent().add(run); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().addObject(para); wordMLPackage.getMainDocumentPart().addParagraphOfText("p1"); wordMLPackage.getMainDocumentPart().addParagraphOfText("p2"); wordMLPackage.save(new File("test.docx"));