簡體   English   中英

使用aspose創建Excel

[英]Creating Excel using aspose

嗨,我正在研究Java項目。

我正在為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();
        }

我正在為Excel api使用aspose-cell.7.0.0 jar文件。

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

  1. 安裝“ Microsoft TrueType核心字體”,然后再次運行該程序。
  2. 從基於命令的Java程序中運行相同的示例。 如果您遇到相同的問題,請在Aspose論壇中報告示例代碼和Java / OS版本。
  3. 嘗試使用最新版本的Aspose.Cells for Java,該問題可能已經解決。

我與Aspose一起擔任開發人員推廣人員。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM