How to set background color (Page Color) for word document (.doc or .docx) in Java?

前端 未结 2 1614
一整个雨季
一整个雨季 2021-01-07 15:39

By some libraries like http://poi.apache.org , we could create word document with any text color, but for background or highlight of the te

2条回答
  •  死守一世寂寞
    2021-01-07 15:58

    We Only need to add these 3 lines to set the background color for Word documents by XWPF. We have to set these lines after declaring XWPFRun and it's text color:

    CTShd cTShd = run.getCTR().addNewRPr().addNewShd();
    cTShd.setVal(STShd.CLEAR);
    cTShd.setFill(hex_background_color);
    

提交回复
热议问题