2014-02-06 3 views
3

xdocreport 1.0.3을 사용하고 odt 템플릿을 업로드하고 처리하고 docx 처리 문서를 얻으려고합니다. 어떻게해야합니까?xdocreport를 사용하여 odt를 docx로 변환하는 방법?

public void generateUserReport(long pcCaseId, long currentUserId) throws CMSException{ 
    try { 
    InputStream is = new FileInputStream(CustomTemplate.TEMPLATES_PATH + "test.odt"); 
    IXDocReport report; 
    report = XDocReportRegistry.getRegistry().loadReport(is,TemplateEngineKind.Velocity); 
    IContext context = report.createContext(); 

    FieldsMetadata metadata = new FieldsMetadata(); 
    metadata.addFieldAsImage("signature"); 
    metadata.addFieldAsImage("logo"); 

    Date currentDate = new Date(); 
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/YYYY"); 
    context.put("currentDate", df.format(currentDate)); 

    User user = this.userDAO.loadUser(currentUserId); 
    byte[] signatureByteArr = user.getSignature(); 
    context.put("userName", user.getFullName()); 

    //TODO If exists signature, it will be added, in other case? 
    if (signatureByteArr!=null){ 
     FileOutputStream fos = new FileOutputStream(CustomTemplate.TEMPLATES_PATH + "signature.jpg"); 
     report.setFieldsMetadata(metadata); 
     fos.write(signatureByteArr); 
     FileImageProvider signature = new FileImageProvider(new File(CustomTemplate.TEMPLATES_PATH,"signature.jpg")); 
     context.put("signature", signature); 
    }else{ 
     FileImageProvider noImage = new FileImageProvider(new File(CustomTemplate.TEMPLATES_PATH, "1px.gif")); 
     context.put("signature", noImage); 
    } 

    FileImageProvider logo = new FileImageProvider(new File("TEMPLATES_PATH, logo.gif")); 
    context.put("logo", logo); 

    OutputStream out = new FileOutputStream(new File(CustomTemplate.TEMPLATES_PATH, "OutPut.docx")); 
    report.process(context, out); 
    System.out.println("Success"); 
    } catch (IOException e) { 
    System.out.println("IO exception"); 
    } catch (XDocReportException e) { 
     System.out.println("XDocException"); 
     e.printStackTrace(); 
    } 
} 

내가 OutPut.docx를 얻을 수 있지만, "사실상는"그것이 ODT 문서이며, 마이크로 소프트 오피스는 오류 정보없이 열 수 없습니다 :

나는이 시도. 오픈 오피스는 아무런 문제없이 그것을 엽니 다.

+0

당신이 시도한 것을 보여줄 수 있습니까? – OmniOwl

답변

3

짧은 답변으로 XDocReport는 odt-> docx 변환기을 지원하지 않습니다.

report.process은 변환이 없음을 의미합니다 (docx template-> docx report, odt template-> odt report). 당신의 샘플에서, 생성 된 보고서는 odt입니다 (심지어 docx 확장자로 filename을 설정하더라도). 그래서 OpenOffice는 MS Word가 그것을 열 수 없어도 열 수 있습니다.

보고서를 html, pdf와 같은 다른 형식으로 변환하려면 report.convert을 사용해야하지만, 경우에 따라 XDocReport가 제공하지 않는 docx-> odt 변환기가 필요합니다. 그러나 XDocReport가 모듈화되어 있으므로 자신 만의 docx-> odt 변환기를 개발하고 XDocReport로 연결할 수 있습니다.

+0

고맙습니다, 안젤로. 그러나 나는 이것을 처음 시도한 사람이라고 믿을 수 없다. – Filosssof