0
私はいくつかのコードを試しましたが、空のドキュメントをダウンロードしています。 response.getOutputStream()にHWPFDocumentオブジェクトを書き込もうとすると、Word文書が破損しています。助けが必要。POI、Spring MVC、jqueryを使用して既存のテンプレートを使用してワードドキュメントを生成するには?
jQueryの機能
$.ajax({ type : "GET",
url : urlIpd,
success : function(data) {
$("#dl-frames").attr("src", urlIpd);
},
});
コントローラ方法。事前に
@RequestMapping(value = "/{partLocnId}/{partnerId}/ipdDwnld", method = RequestMethod.GET)
public void ipdDwnld(@PathVariable("partLocnId") String partLocnId, @PathVariable("partnerId") String partnerId, HttpServletResponse response) {
HWPFDocument doc = null;
try {
response.setContentType("application/msword");
response.addHeader("Content-Disposition", "attachment; filename=\"" + partnerId +".doc" + "\";");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream((new File("C:/templates/IPDV14Q117.ImplementationName.doc"))));
doc = new HWPFDocument(fs);
doc.getRange();
Range range = doc.getRange();
range.replaceText("Integration Process Design", "TEST");
//ServletOutputStream fos = (response.getOutputStream()); //using this document will get corrupt.
FileOutputStream fos = new FileOutputStream(new File(partnerId+".doc")); // generates blank document
doc.write(fos);
fos.close();
doc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
おかげで
3.0.1は絶対に古代です!あなたは本当にそのような古いバージョンを使用すべきではありません、可能であれば最新のバージョンを使用する必要があります – Gagravarr