2015-04-17 53 views
0

嗨我正在開發一個Java項目。使用aspose創建Excel

我正在爲Excel API使用aspose-cell.7.0.0 jar文件。

但是我在啓動save方法時遇到異常。

這是版本錯誤?

異常

org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [com.aruvio.test.Test] in context with path [/NewDataLoader] threw exception [Servlet execution threw an exception] with root cause 
java.lang.IncompatibleClassChangeError: Found interface sun.font.FontManager, but class was expected 
    at com.aspose.cells.a.c.cf.p(Unknown Source) 
    at com.aspose.cells.a.c.cf.<init>(Unknown Source) 
    at com.aspose.cells.b.a.b.g.<init>(Unknown Source) 
    at com.aspose.cells.b.a.b.g.<init>(Unknown Source) 
    at com.aspose.cells.cm.a(Unknown Source) 
    at com.aspose.cells.cm.a(Unknown Source) 
    at com.aspose.cells.cm.a(Unknown Source) 
    at com.aspose.cells.Worksheet.autoFitColumns(Unknown Source) 
    at com.aruvio.test.Test.doGet(Test.java:89) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at com.aruvio.servlet.FilterRequest.doFilter(FilterRequest.java:79) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

編碼

//Create a new Workbook.   
     Workbook workbook = new Workbook(); 

     //Get the first worksheet. 
     Worksheet sheet = workbook.getWorksheets().get(0); 


     //Get the worksheet cells collection. 
     Cells cells = sheet.getCells(); 


     //Input a value. 
     cells.get("B3").setValue("Choose Dept:"); 

     Style style = cells.get("B3").getStyle(); 
     style.getFont().setBold(true); 
     //Set it bold. 
     cells.get("B3").setStyle(style); 


     //Input some values that denote the input range for the combo box. 
     cells.get("A2").setValue("Boy1"); 
     cells.get("A3").setValue("Boy2"); 
     cells.get("A4").setValue("Boy3"); 
     cells.get("A5").setValue("Boy4"); 
     cells.get("A6").setValue("Boy5"); 
     cells.get("A7").setValue("Boy6"); 

     //Add a new list box. 
     com.aspose.cells.ListBox listBox = (com.aspose.cells.ListBox)sheet.getShapes().addShape(MsoDrawingType.LIST_BOX,3, 3, 1,0, 100, 122); 

     //Set the linked cell; 
     listBox.setLinkedCell("A1"); 

     //Set the input range. 
     listBox.setInputRange("=A2:A7"); 

     //Set the Placement Type, the way the list box is attached to the cells. 
     listBox.setPlacement(PlacementType.FREE_FLOATING); 

     //Set the list box with 3-D shading. 
     listBox.setShadow(true); 

     //Set the selection type. 
     listBox.setSelectionType(SelectionType.SINGLE); 

     //AutoFit Columns 
     try { 
      sheet.autoFitColumns(); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     //Saves the file. 
     try { 
      workbook.save("D:\\tstlistbox.xls"); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

我使用的Aspose - cell.7.0.0 jar文件爲Excel API。

回答

0

看起來字體問題,請嘗試以下

  1. 安裝「微軟的TrueType核心字體」,並再次運行程序。
  2. 從基於Java的命令程序運行相同的示例。如果您看到相同的問題,請使用示例代碼和Java/OS版本在Aspose forums中報告。
  3. 嘗試使用最新版本的Aspose.Cells for Java,問題可能已經被修復。

我使用Aspose作爲Developer Evangelist。