接上一篇poi导出word http://www.cnblogs.com/xiufengd/p/4708680.html。
public static void setAuto(XWPFDocument doc) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{ List<POIXMLDocumentPart> list = doc.getRelations(); //设置一些Word文档的兼容属性 for(POIXMLDocumentPart p:list) { if(p instanceof XWPFSettings) { XWPFSettings settings = (XWPFSettings)p; Field field = settings.getClass().getDeclaredField("ctSettings"); field.setAccessible(true); //生成新的Word设置类CTSettings的对象实例,设置UlTrailSpace,使得word为行尾的空格显示下划线 CTSettings att = CTSettings.Factory.newInstance(); att.addNewCompat().addNewUlTrailSpace().setVal(STOnOff.ON); field.set(settings, att); break; } } }
时间: 2024-11-02 00:57:38