2013-04-02 47 views
3

我使用這些JAR文件到Excel和Power點文件轉換爲PDF
aspose.slides-6.7.0.jar
aspose.slides-6.7.0-JDK14的.jar
的Aspose細胞-7.3.4.jar
的Aspose是perdectly轉換pptxls文件,但它拋出異常的xlsxpptx文件。
現在我正在使用試用版。
這是由於試用版本還是我使用舊版本的Aspose?
這是例外
的Aspose XLSX和PPTX文件轉換例外

SEVERE: com.aspose.slides.UnsupportedFormatException: The file is ZIP archive. It can be Microsoft PowerPoint 2007 PPTX presentation. 
    at com.aspose.slides.eQ.break(Unknown Source) 
    at com.aspose.slides.eQ.<init>(Unknown Source) 
    at com.aspose.slides.eS.byte(Unknown Source) 
    at com.aspose.slides.eS.new(Unknown Source) 
    at com.aspose.slides.eS.<init>(Unknown Source) 
    at com.aspose.slides.uj.do(Unknown Source) 
    at com.aspose.slides.uj.<init>(Unknown Source) 
    at com.aspose.slides.Presentation.do(Unknown Source) 
    at com.aspose.slides.Presentation.<init>(Unknown Source) 
    at com.aspose.slides.Presentation.<init>(Unknown Source) 
    at com.delta.MiDAS.commonlibs.Utility.convertPPT(Utility.java:58) 
    at com.delta.MiDAS.controllers.DocumentInsertController.loadDocForPreview(DocumentInsertController.java:485) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at com.sun.el.parser.AstValue.invoke(AstValue.java:254) 
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302) 
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) 
    at javax.faces.component.UICommand.broadcast(UICommand.java:315) 
    at javax.faces.component.UIData.broadcast(UIData.java:1093) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:77) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) 
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) 
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) 
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) 
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) 
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) 
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) 
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) 
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71) 
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) 
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 
    at java.lang.Thread.run(Thread.java:722) 

這裏是我的轉換代碼

public void convertPPT(String Path) throws Exception{ 
      Presentation pres = new Presentation(Path); 
      Integer index=Path.lastIndexOf("."); 
      String destPath=Path.substring(0, index)+".pdf"; 
      pres.saveToPdf(destPath); 
      System.out.println("PPT file converted to PDF"); 

     } 

     public void convertExcel(String Path) throws Exception{ 

      Workbook workbook = new Workbook(Path); 

      //Save the document in PDF format 
      Integer index=Path.lastIndexOf("."); 
      String destPath=Path.substring(0, index)+".pdf"; 

      workbook.save(destPath, FileFormatType.PDF); 

      System.out.println("excel converted to doc"); 

     } 

有什麼建議?

回答

4

不,這個例外並不是因爲使用試用版或Aspose的舊版本(雖然推薦使用的版本總是最新版本,但應該使用Aspose.Cells for Java 7.4.2和Aspose.Slides for Java的7.2.0)

如需辦理XLSX和PPTX文件,你將不得不修改您的轉換方法如下:

public void convertPPTToPDF(String Path) throws Exception 
{ 
    String extension = ""; 
    Integer index = Path.lastIndexOf("."); 
    if (index > 0) { 
     extension = Path.substring(index+1); 
    } 

    if (extension.equals("ppt")) 
    { 
     Presentation pres = new Presentation(Path); 
     String destPath=Path.substring(0, index)+".pdf"; 
     pres.saveToPdf(destPath); 
    } 
    else if (extension.equals("pptx")) 
    { 
     //Instantiate a PresentationEx object that represents a PPTX file 
     PresentationEx pres = new PresentationEx(Path); 
     String destPath=Path.substring(0, index)+".pdf"; 

     //Saving the PPTX presentation to PDF document 
     pres.save(destPath, com.aspose.slides.SaveFormat.Pdf); 
    } 
    System.out.println("Powerpoint file converted to PDF successfully"); 
} 

public void convertExcelToPDF(String Path) throws Exception 
{ 
    String extension = ""; 
    Integer index = Path.lastIndexOf("."); 
    if (index > 0) { 
     extension = Path.substring(index+1); 
    } 

    if (extension.equals("xls")) 
    { 
     Workbook workbook = new Workbook(Path); 

     //Save the document in PDF format 
     String destPath=Path.substring(0, index)+".pdf"; 
     workbook.save(destPath, FileFormatType.PDF); 
    } 
    else if (extension.equals("xlsx")) 
    { 
     //Createing and XLSX LoadOptions object 
     LoadOptions loadOptions = new LoadOptions(FileFormatType.XLSX); 

     //Creating an Workbook object with 2007 xlsx file path and the loadOptions object 
     Workbook workbook = new Workbook(Path, loadOptions); 
     String destPath=Path.substring(0, index)+".pdf"; 
     workbook.save(destPath, FileFormatType.PDF); 
    } 

    System.out.println("Excel file converted to PDF successfully"); 
} 

我已經檢查了更新的方法進行PPT,PPTX,XLS做工精細和最新版本的Aspose.Cells和Aspose.Slides for Java的xlsx文件。

我是Aspose的開發人員傳道人。

+1

非常感謝:)它真的幫了我:) – Despicable

+0

@iqbal謝謝,這也幫助了我。你們可能會考慮在指定pptx文檔的情況下改進從Aspose.Slides.Presentation的構造函數拋出的錯誤。 – newbyca

相關問題