2011-08-03 2 views

답변

8

는이 같은 헤더 및 내용 유형을 설정해야합니다

response.setHeader "Content-disposition", "attachment;filename=myExcel.xls" 
    response.contentType = "application/vnd.ms-excel" 

그런 다음 응답에서 콘텐츠를 스트리밍.

편집 : jxl jar

시도를 추가하는 당신이 가지고있는 javadoc

+0

사이트 사용자로서 콘텐츠 길이 헤더의 장점도 사용하고 싶습니다. – Basilevs

2
response.setContentType("APPLICATION/OCTET-STREAM"); 
response.setHeader("Content-Disposition", "Attachment;Filename=\"MyFile.xls\""); 
0

에 설명

response.contentLength = 100 

내용 길이 : 당신은 콘텐츠 길이를 설정해야하는 경우 이 코드 :

@WebServlet("/Reportexel") 
public class Reportexel extends HttpServlet 
{ 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    { 
     try 
     { 
      response.setHeader("Content-disposition", "attachment; filename=kbdemo.xls"); 
      response.setContentType("application/vnd.ms-excel"); 
      WritableWorkbook workbook = Workbook.createWorkbook(response.getOutputStream());  
      WritableSheet worksheet = workbook.createSheet("Sheet 1",0); 

      Label lbl = new Label(1,1,"Hello"); 
      Label lbl1 = new Label(1,2,"Hi..."); 

      worksheet.addCell(lbl); 
      worksheet.addCell(lbl1); 

      workbook.write(); 
      workbook.close(); 
     } 
     catch(Exception e) 
     { 
      System.err.println("Main Error : "+e); 
     } 
    } 
} 
관련 문제