Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:02:47+00:00 2026-05-26T11:02:47+00:00

I would like to find a list paragraph (starting with a. ), and append

  • 0

I would like to find a list paragraph (starting with a. ), and append another list item to this list (it depend on the text of first list element).
I have tried many ways of creating new paragraph, but all what I achieved is that new list elements are created, but org.docx4j.wml.Text objects are appended to paragraph the new paragraph was appended. The new paragraph text is empty. How can be new list element created and appended to the right element?

  • a. list element 1 |test| //|test| should be appended to b.
  • b. //new items are created, but there is no text
  • c.
  //traverse through a document
    public List<Object> apply(Object obj) {
       if (obj instanceof org.docx4j.wml.P) { 
          if (p.getPPr() != null) {
             if (p.getPPr().getPStyle() != null) {
                if ((p.getPPr().getPStyle().getVal().equals("Akapitzlist"))) {
                   //there is a list paragraph
                         ObjectFactory factory = Context.getWmlObjectFactory();
                         Object deepCopy = XmlUtils.deepCopy(obj);
                    //Create the paragraph 
                    org.docx4j.wml.P para = factory.createP();

                    // Create the text element 
                    org.docx4j.wml.Text t = factory.createText();
                    t.setValue("|test|");

                    // Create the run 
                    org.docx4j.wml.R run = factory.createR();
                    run.getContent().add(t);
                    para.getContent().add(run);
                    //add new paragraph to the document
                    ((org.docx4j.wml.P) obj).getContent().add(para);

    }...}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:02:48+00:00Added an answer on May 26, 2026 at 11:02 am

    My solution, just append to the body with incremented index. I’ am creating deep copy to preserwe style.

        public List<Object> apply(Object obj) {
    
    
        Object deepCopy = null;
    
    
    
        if (obj instanceof org.docx4j.wml.P) {
    
            org.docx4j.wml.P p = (org.docx4j.wml.P) obj;
    
    
            if (p.getPPr() != null) {
                if (p.getPPr().getPStyle() != null) {
                    if ((p.getPPr().getPStyle().getVal().equals("Akapitzlist")) && (akapListCounter < 10)) {
    
                        if (((org.docx4j.wml.P) obj).getPPr().getPStyle() != null) {
                            if ((((org.docx4j.wml.P) obj).getPPr().getPStyle().getVal().equals("Akapitzlist"))) {
                                deepCopy = XmlUtils.deepCopy(obj);
                                akapListCounter++;
                                int indexOf = wmlDocumentEl.getBody().getContent().indexOf(obj);
    
    
                                List<Object> content = ((org.docx4j.wml.P) deepCopy).getContent();
                                for (Object el : content) {
                                    System.out.println("class1:" + el.getClass().toString());
                                    if (el instanceof org.docx4j.wml.R) {
                                        List<Object> subc = ((org.docx4j.wml.R) el).getContent();
                                        for (Object r : subc) {
                                            ((javax.xml.bind.JAXBElement) r).setValue("tetetete");
                                        }
                                    }
    
                                }// end for
    
    
                                wmlDocumentEl.getBody().getContent().add(indexOf + 1, deepCopy);
    
    
                            }
                        }//end get style
    
                    }
                } 
            } else {}
    
    
        }
    
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to find the first valid image among a list in ruby.
I have a list of postcodes that includes duplicates. I would like to find
A SocketException has a SocketErrorCode and NativeErrorCode. I would like to find a list
I would like to find a replacement for list.com, specifically the ability to accept
I would like to know where I can find the list of properties settable
I would like to find out, in JavaScript, which element currently has focus. I've
I would like to find a list of mobile devices in the world on
I have a table with an ip address column. I would like to find
Given a two-dimensional list, I would like to find everything that contains a sublist.
Having a sorted list and some random value, I would like to find in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.