生成的Excel文件(JExcel / Apache POI)上ZK API的Range.insert上的NullPointerException

时间:2022-01-12 20:24:02

Favor for a friend, here's her query:

对朋友有利,这是她的疑问:

Hi! I am currently using jexcelapi to create excel files and then I read them using zk spreadsheet. I tried the code found in the documentation for inserting columns and shifting cells to the right but unfortunately, a null pointer exception shows up whenever I try to insert/shift cells. I also tried uploading the excel files I created using jexcelapi to the zssapp (just to be sure) but a null pointer also shows up. But when I try to read excel files created by MS Excel, it works fine. Has anyone encountered this problem before? Any help would greatly be appreciated. PS: I also tried using POI to create files. I also encounter a null pointer exception.

嗨!我目前正在使用jexcelapi创建excel文件,然后我使用zk电子表格阅读它们。我尝试了在文档中找到的用于插入列和向右移位单元格的代码,但遗憾的是,每当我尝试插入/移位单元格时,就会出现空指针异常。我也尝试将使用jexcelapi创建的excel文件上传到zssapp(只是为了确定),但是空指针也会显示出来。但是当我尝试读取由MS Excel创建的excel文件时,它工作正常。以前有人遇到过这个问题吗?任何帮助将不胜感激。 PS:我也尝试使用POI来创建文件。我也遇到空指针异常。

Here is the error:

这是错误:

  java.lang.NullPointerException
at org.zkoss.poi.hssf.record.XFExtRecord.cloneXFExtFrom(XFExtRecord.java:91)
at org.zkoss.poi.hssf.usermodel.HSSFCellStyle.cloneStyleFrom(HSSFCellStyle.java:835)
at org.zkoss.poi.hssf.usermodel.HSSFCellStyle.cloneStyleFrom(HSSFCellStyle.java:825)
at org.zkoss.zss.model.impl.BookHelper.copyFromStyleExceptBorder(BookHelper.java:3308)
at org.zkoss.zss.model.impl.HSSFSheetImpl.shiftColumnsRange(HSSFSheetImpl.java:601)
at org.zkoss.zss.model.impl.BookHelper.insertHSSFRange(BookHelper.java:1942)
at org.zkoss.zss.model.impl.BookHelper.insertRange(BookHelper.java:1931)
at org.zkoss.zss.model.impl.RangeImpl.insert(RangeImpl.java:649)
at data.InitWindow.onClick$shiftCellRight(InitWindow.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:81)
at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:305)
at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:328)
at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3022)
at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1603)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1387)
at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1107)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:563)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:457)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:465)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

And here is the code I use to create files. What I do here is create an excel file whenever a form is created:

这是我用来创建文件的代码。我在这里做的是在创建表单时创建一个excel文件:

public void createExcel(Integer formID, String loc){
    try {
        File path = new File(loc);
        if (!path.exists()) {
            boolean status = path.mkdirs();
        }
        String filename = loc + formID +".xls";
        WorkbookSettings ws = new WorkbookSettings();
        ws.setLocale(new Locale("en", "EN"));
        WritableWorkbook workbook;
        workbook = Workbook.createWorkbook(new File(filename), ws);
        workbook.createSheet("Sheet1", 0);
        workbook.write();
        workbook.close();  
    } catch (IOException e) {
        e.printStackTrace();
    } catch (WriteException e) {
        e.printStackTrace();
    }   
}

From what I've found out, she's using a gwt frame as a bridge to use zk classes.

根据我的发现,她使用gwt框架作为桥梁来使用zk类。

The original post of this query can be found here: http://www.zkoss.org/forum/listComment/15683

可以在此处找到此查询的原始帖子:http://www.zkoss.org/forum/listComment/15683

Thanks very much guys!

非常感谢你们!

1 个解决方案

#1


0  

Here is where the error originated:

这是错误发生的地方:

public void onClick$insertCol() {
    int tRow = currSheet.getFirstRowNum();
    int bRow = currSheet.getPhysicalNumberOfRows();
    Ranges.range(currSheet, tRow, colIndex, bRow, colIndex).insert(Range.SHIFT_RIGHT, Range.FORMAT_RIGHTBELOW);
}

The error also shows up if I shift cells to the right.

如果我将单元格向右移动,也会出现错误。

#1


0  

Here is where the error originated:

这是错误发生的地方:

public void onClick$insertCol() {
    int tRow = currSheet.getFirstRowNum();
    int bRow = currSheet.getPhysicalNumberOfRows();
    Ranges.range(currSheet, tRow, colIndex, bRow, colIndex).insert(Range.SHIFT_RIGHT, Range.FORMAT_RIGHTBELOW);
}

The error also shows up if I shift cells to the right.

如果我将单元格向右移动,也会出现错误。