首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用aspose创建Excel

使用aspose创建Excel
EN

Stack Overflow用户
提问于 2015-04-17 09:51:43
回答 1查看 2.9K关注 0票数 0

嗨,我在做一个Java项目。

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

但是,当我启动保存方法时,我会得到一个异常。

这是版本错误吗?

异常

代码语言:javascript
复制
 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)

编码

代码语言:javascript
复制
//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使用aspose-cell.7.0.0 jar文件。

EN

回答 1

Stack Overflow用户

发布于 2015-04-18 18:21:59

它看起来像字体问题,尝试下面的

  1. 安装“微软TrueType核心字体”,并再次运行该程序。
  2. 从基于命令的Java程序中运行相同的示例。如果您看到同样的问题,请用示例代码和Java/OS版本在阿斯波斯论坛中报告。
  3. 尝试最新的Aspose.Cells for Java版本,这个问题可能已经解决了。

我和Aspose合作,做开发人员的布道者。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29695921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档