How to change content inside table/Nested table in docx file using apache POI
Asked Answered
M

0

1

I am using apache POI to change the styling of data in docx file. I am able to change the text styles on normal paragraphs but when it comes to the content that is present in table, it does not change.

 public static void changeStyle(XWPFParagraph paragraph, Map<String, String> translation_keyDataMap,JSONObject style) 
  {
     for (int runNumber = 0; runNumber < paragraph.getRuns().size(); runNumber++) 
       {
           XWPFRun run = paragraph.getRuns().get(runNumber);
            String runText= run.getText(0);

            if(runText!=null)
            {
                runText=runText.replace(" "," ");
                run.setColor(style.getString("color"));
                run.setFontFamily(style.getString("font"));

            }

        }

    }

Screenshot of the output docx file where table content has not changed to RED

Mozarab answered 11/12, 2020 at 6:17 Comment(3)
You'll need to find all the runs that between them contain your text - Word almost never merges runs back together when formatting no longer differs, so you need to cope with this Word "feature"Xenos
the thing is, even the words are split in different runs, so finding the word in the run won't work, also if i apply loop to search any word then it will change font of that particular word wherever it finds it.Mozarab
@Xenos i have modifyed the question with few more details, need help hereMozarab

© 2022 - 2024 — McMap. All rights reserved.