我想像这样导出 odsfile
但我真的得到了出口是这个(标题有额外的词)
这是我的代码,感谢您的任何建议
@RequestMapping(value = "/export", method = RequestMethod.POST)
public @ResponseBody void exportOds(Long questionId,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
VoteQuestion q = voteManager.getQuestion(questionId);
TableModel model = new DefaultTableModel(1000,1000);
File file = File.createTempFile("temp", ".ods");
model.setValueAt(q.getQuestion(), 0, 0);
int row = 2;
for (VoteOption opt : q.getOptions()) {
model.setValueAt(opt.getDescription(), row, 0);
model.setValueAt(opt.getVotes(), row++, 1);
}
SpreadSheet.createEmpty(model).saveAs(file);
String fileName = "投票結果";
String encodeFileName = FilenameEncoder.getInstance(request)
.encodeFileName(fileName + ".ods");
response.setHeader("Content-Disposition",
"attachment; filename=" + encodeFileName);
FileInputStream in = null;
OutputStream out = null;
try {
out = response.getOutputStream();
in = new FileInputStream(file);
IOUtils.copy(in, out);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
file.deleteOnExit();
}
}