poi导入word纯文本
public List exportWord(List<Question> list,String filePath){
List<String> newlist = new ArrayList<>();// XWPFDocument document= new XWPFDocument(); List<Question.QuestionOption> qolist=null; for (int i = 0; i < list.size(); i ) { newlist.add(list.get(i).getStem() "n"); qolist=list.get(i).getQuestionOptionList(); if(qolist!=null && qolist.size()>0){ for (int j = 0; j < qolist.size(); j ) { newlist.add(qolist.get(j).getOptionCont() "n"); } } } FileOutputStream out=null; try { out = new FileOutputStream(new File(filePath)); } catch (FileNotFoundException e) { e.printStackTrace(); } if(list!=null && list.size()>0){ //formatTitleWord(document,list.get(0)); formatParagraphWord(document,newlist); } try { document.write(out); out.close(); } catch (IOException e) { e.printStackTrace(); } return newlist;
}
/** * 段落样式 */ public static void formatParagraphWord(XWPFDocument document,List<String> contentList){ //段落 XWPFParagraph firstParagraph = document.createParagraph(); XWPFRun run = firstParagraph.createRun(); if(contentList!=null && contentList.size()>0){ for (int i = 0; i < contentList.size(); i ) { run.setText(contentList.get(i)); } } run.setColor("000000"); run.setFontSize(12); //设置段落背景颜色 /*CTShd cTShd = run.getCTR().addNewRPr().addNewShd(); cTShd.setVal(STShd.CLEAR); cTShd.setFill("");*/ }