itext可以生成word、pdf,但是不能读取已有的word内容。
/**
* 生成word文档
*
* @param sj
* @return
*/
private String writeToWord(ZjclSj sj) throws DocumentException, IOException {
ResourceVO vo = ResourceManager.getResource("/temp/shijuan.doc");
// 找出试卷模板
Document document = new Document(PageSize.A3.rotate()); // 设置纸张大小 横向
String path = "/temp/" + sj.getSjmc() + ".doc";
String filePath = ResourceManager.getRealPath() + path;
// 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中
RtfWriter2 rtfWriter = RtfWriter2.getInstance(document,
new FileOutputStream(filePath));
document.open();
document.add(new Paragraph(org.apache.commons.io.FileUtils
.readFileToString(vo.getFile())));
List<StkStxx> list = sj.getSt();
for (StkStxx stkStxx : list) {
Paragraph paragraph = new Paragraph(new Phrase(stkStxx.getTmnr()));
paragraph.setAlignment(Element.ALIGN_LEFT);
paragraph.setSpacingBefore(10);
document.add(paragraph);
}
document.close();
return path;
}
--或者查看团委管理的结果查询导出