萧十郎
只是注意到您由于IE8 / 9而无法使用它,但是我还是会继续提交...也许有人觉得它有用实际上,这可以通过浏览器使用完成blob。注意Promise中的responseType和代码success。$http({ url: 'your/webservice', method: "POST", data: json, //this is your json data string headers: { 'Content-type': 'application/json' }, responseType: 'arraybuffer'}).success(function (data, status, headers, config) { var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}); var objectUrl = URL.createObjectURL(blob); window.open(objectUrl);}).error(function (data, status, headers, config) { //upload failed});尽管有一些问题,例如:它不支持IE 8和9:它会打开一个弹出窗口,以打开objectUrl可能被阻止的人生成奇怪的文件名确实有效!用以下方法测试了PHP中的服务器端代码。我确定您可以在Java中设置类似的标头:$file = "file.xlsx";header('Content-disposition: attachment; filename='.$file);header('Content-Length: ' . filesize($file));header('Content-Transfer-Encoding: binary');header('Cache-Control: must-revalidate');header('Pragma: public');echo json_encode(readfile($file));浏览器使以这种方式保存数据变得更加困难。一种不错的选择是使用filesaver.js。它为提供了跨浏览器的实现saveAs,并且应替换上述Promise中的某些代码success。