期望返回excel文件但响应未正确编码以返回excel文件

时间:2017-06-02 15:31:23

标签: excel rest get apache-poi

我发送HTTP GET请求,期望将Excel工作簿作为响应。但是,响应格式不正确。我期待下载提示作为响应

@GET
@Path("bulkimporttemplate")
@Produces("application/vnd.ms-excel")
public Response getClientTemplate() throws IOException {
    final XSSFWorkbook wb = new XSSFWorkbook();
    WorkbookPopulatorFactory.createWorkbookPopulator("Client", "ClientTemplate");
    StreamingOutput streamOutput = new StreamingOutput() {
        @Override
        public void write(OutputStream out) throws IOException, WebApplicationException {
            wb.write(out);
        }
    };
    ResponseBuilder response = Response.ok(streamOutput, "application/vnd.ms-excel");
    response.header("content-disposition", "attachment; filename=clientTemplate.xls");
    return response.build();
}

enter image description here

0 个答案:

没有答案