Java Angular2-下载从RestService收到的XLS

Java Angular2-下载从RestService收到的XLS,java,excel,angular,apache-poi,Java,Excel,Angular,Apache Poi,我想用apachePOI生成一个Excel(xls,xlsx)文件。我制作了如下代码 @RequestMapping(value = "/export", method = RequestMethod.GET) public void exportXlsx(HttpServletResponse response) { // getting datas for file try { Workbook wb = //creating the file

我想用apachePOI生成一个Excel(xls,xlsx)文件。我制作了如下代码

@RequestMapping(value = "/export", method = RequestMethod.GET)
public void exportXlsx(HttpServletResponse response) {

    // getting datas for file
    try {

        Workbook wb = //creating the file
        response.setHeader("Content-Disposition", "attachment; filename=" + entity.getType() + ".xls");
        wb.write(response.getOutputStream());
    } catch (IOException | EncryptedDocumentException e) {
        Logger.getLogger(e.getStackTrace().toString());
    }
}
该服务正在运行,如果我调用该服务,将返回正确的文件。我需要为这个服务添加一个使用Angular2的GUI。 调用此服务,如:

    let headers = new Headers({ 'Content-Type': 'application/json', 'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    let options = new RequestOptions({ headers: headers });
    return this.http.post("URL", options);
我收到一些错误,如:406(不可接受)。
我尝试了在论坛上找到的所有可能的解决方案,但没有成功。

您的Accept标头表明响应具有xslx文件格式(
application/vnd.openxmlformats officedocument.spreadsheetml.sheet
),但您发送的文件具有扩展名
.xls

将文件扩展名更改为
.xlsx
或使用mime类型
应用程序/vnd.ms excel