2012-08-01 2 views
0

서버 측 자바 스크립트 (Russ Maher에게 감사)를 사용하여 Excel 파일을 만드는 XPage가 있습니다. 브라우저에서 로컬로 XPage를 실행하는 경우 C : 드라이브에 저장하는 방법을 알고 있지만 서버에 저장하지 않고 서버에서 실행 중일 때 사용자의 컴퓨터에 저장하는 방법을 모릅니다. 다음 코드는 서버의 관점에서 저장하는 데 사용됩니다.엑셀 파일을 브라우저에서 로컬 드라이브로 저장하는 방법

var fileOut = new java.io.FileOutputStream(directory+fileName); 
xl.write(fileOut); 
fileOut.close(); 

어떻게 사용자의 드라이브로 안내 할 수 있습니까? 대신의 FileOutputStream에 Excel 통합 문서를 작성

답변

0

Paul Calhoun이 내가 원하는 스프레드 시트를 만들기 위해 마사지 한 샘플 코드를 보냈습니다. 내가하지 못했던 일이 무엇인지 모르겠지만, 지금은 이것이 솔루션의 핵심이라고 생각합니다. FileOutputStream 또는 ByteArrayOutputStream 대신 OutputStream을 사용하는 것만으로도 충분합니다. 누군가 다른 사람이 묻는 시간, 희망,이 문제가 발생하고있는 경우

// The Faces Context global object provides access to the servlet environment via the external content 
var extCont = facesContext.getExternalContext(); 
// The servlet's response object provides control to the response object 
var pageResponse = extCont.getResponse(); 
//Get the output stream to stream binary data 
var pageOutput = pageResponse.getOutputStream(); 

// Set the content type and headers 
pageResponse.setContentType("application/x-ms-excel"); 
pageResponse.setHeader("Cache-Control", "no-cache"); 
pageResponse.setHeader("Content-Disposition","inline; filename=" + fileName); 
//Write the output, flush the buffer and close the stream 
wb.write(pageOutput); 
pageOutput.flush(); 
pageOutput.close(); 

// Terminate the request processing lifecycle. 
facesContext.responseComplete(); 

나는 기꺼이 도움을 제공 할 것입니다, 나는

1

, 당신은 그것을이있는 ByteArrayOutputStream에 기록한다 :

ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 
xl.write(outputStream); 

당신은 아마 당신의 XPage에서 XAgent에 연결 한 후 출력을 생성하기 위해 XAgent를 사용해야합니다. 어쩌면 this blog entry by Declan Lynchthis answer on how to do it in a servlet을 결합하면 올바른 방향으로 인도 할 수 있습니다.

+0

당이 옳다 .... 일이 다른 무엇을 더 이해할 것이다. OpenNTF의 XSnippets에서 XAgent 스 니펫을 살펴보십시오. 출력 스트림을 제공합니다. 따라서 자신의 스트림을 만드는 대신 메서드에 매개 변수로 전달하십시오. 그러면 content-disposition 헤더가 파일 이름을 결정할 수 있습니다. 사용자가 저장을 확인해야한다는 점에 유의하십시오. 또한 고급 Excel 출력 기능을위한 Apache POI를 살펴보십시오. – stwissel

+0

감사합니다. Per. @stwissel Apache POI를 사용하고 있지만, Russ Maher의 구현을 취한 상태에서 조금이라도 확장 한 실제 아마추어입니다. –

관련 문제