Search code examples
javaapache-poipowerpointhighlight

How to set text hightlight using Apache POI PPT API?


I'm using apache poi to process ppt.I can get the CTTextCharacterProperties of a CTRegularTextRun by using method CTRegularTextRun's getRPr(),and then I can find a method setHighlight(CTColor var1) in interface CTTextCharacterProperties,but I don't know how to make text content being highlighted.does anyone can help me?


Solution

  • CTTextParagraph paragraph=new CTTextParagraph();
    List<CTRegularTextRun> rList = paragraph.getRList();
    for(CTRegularTextRun run:rList){
       CTTextCharacterProperties rPr=run.getRPr();
       CTColor ctColor=rPr.isSetHighlight()==true?rPr.getHighlight():rPr.addNewHighlight();
       CTSRgbColor srgbClr=ctColor.isSetSrgbClr()==true?ctColor.getSrgbClr():ctColor.addNewSrgbClr();
       byte[] rgbBytes = {(byte) Color.GREEN.getRed(), (byte) Color.GREEN.getGreen(), (byte) Color.GREEN.getBlue()};
       srgbClr.setVal(rgbBytes);
    }