4
컨트롤러 메서드에 오류가 없는데도 브라우저에서 Excel 파일을 다운로드 할 수 없습니다.봄 MVC 3 Excel 파일을 다운로드하십시오.
@RequestMapping(value = "/getExcelFile", method = RequestMethod.GET, produces="application/json")
public @ResponseBody HttpEntity<byte[]> getUserDetailsExcelFile(@RequestParam Long id) {
try {
byte[] wb = ExcelReportView.buildExcelDocument(data);
HttpHeaders header = new HttpHeaders();
header.setContentType(new MediaType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
header.set("Content-Disposition",
"attachment; filename=test.xls");
header.setContentLength(wb.length);
return new HttpEntity<byte[]>(wb, header);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
방화범으로부터 정보 요청을 받았습니다.
Request Method:GET Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:org.cups.sid=ed8f7540d976ccc90b85954f21520861; org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=fr; __ngDebug=true; JSESSIONID=tqi3ofownl17
Host:localhost:8888
Referer:http://localhost:8888/
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
id:1
Response Headersview source
Cache-Control:no-cache
Content-Disposition:attachment; filename=test.xls
Content-Length:1849
Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
및 콘텐츠
��A����\p B�a=���=h\:�#[email protected]�"��1���Arial1���Arial1���Arial1���Arial"$"#,##0_);("$"#,##0)"$"#,##0_); [Red]("$"#,##0) "$"#,##0.00_);("$"#,##0.00)% "$"#,##0.00_);[Red]("$"#,##0.00),*'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)5)0_("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)4,/_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)=+8_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)��� � ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� ��� �� � � �+�� �� �)�� �� �,�� �� �*�� �� � �� �� ������������������`��
Users Details���c
First Name Last NameEmailPhone AddressLast AppointmentAppointment Status� K ��
d����MbP?_*+��%������"d,,�?�?U���� � �� �v>�@e
그래서 어떻게 해야할지 모르겠어요 응답
의, 나는 브라우저가 나에게 폴더에있는 파일을 sauvgader 수있는 선택권을 제공합니다.header.set("Content-Disposition", "attachment; filename=test.xls");
하기에 "첨부 파일"을 변경해보십시오 "인라인 :
당신에게
'produce' (JSON) 매개 변수는 응답 내용 유형 헤더 (XLS)와 모순됩니다. – acdcjunior
나는 AbstractExcelView를 사용하기에 sugest할만한 자격이있다. http://www.mkyong.com/spring-mvc/spring-mvc-export-data-to-excel-file-via-abstractexcelview/ –
@acdcjunior 나는 [생산한다. ] (JSON) 항상 동일한 문제가 xlsx에 대한 – badri