我不能让ZK中的WorkbookFactory工作

时间:2013-08-06 09:50:28

标签: apache-poi zk

我是zk编程的新手..现在我正在使用Eclipse Indigo来开发它。 我正在尝试导入Excel .xlsx文件,但它不起作用..我收到错误消息org/apache/poi/ss/usermodel/WorkbookFactory

这是我的.zul代码

 <?page title="import excel" contentType="text/html;charset=UTF-8"?><zk>
<window id="win" title="import excel" border="normal">
    <listbox  width="700px" id="box" mold="paging" pageSize="50" sizedByContent="true" span="true">

    </listbox>

    <button label="Load Excel to listview" upload="true,maxsize=300">
        <attribute name="onUpload"><![CDATA[

            import java.io.File;
            import org.zkoss.io.Files;
            import org.zkoss.util.media.Media;

            String path = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/");
            //alert(path);
            Media media = event.getMedia();

            Files.copy(new File(path+ "upload\\" + media.getName()), media.getStreamData());
            com.function.ZKextend zke=new com.function.ZKextend();
            //zke.ImportExcelProd(win,"box",media);
            zke.ImportExcel(win,"box",media);


        ]]></attribute>
    </button>
    <separator />
</window>
</zk>

这是我导入excel .xlsx文件的功能..

public void ImportExcel(Window nmWindow, String nmListbox, Media media) throws Exception{


    /* We should now load excel objects and loop through the worksheet data */
    FileInputStream input_document = new FileInputStream(new java.io.File("")+Executions.getCurrent().getDesktop().getWebApp().getRealPath("/")+"upload/"+media.getName());
    Workbook my_xls_workbook = WorkbookFactory.create(input_document);
    Sheet my_worksheet = my_xls_workbook.getSheetAt(0);

    Iterator<Row> rowIterator = my_worksheet.iterator(); 

    Listbox list = (Listbox) nmWindow.getFellow(nmListbox);
    list.getItems().removeAll(list.getItems());

    while(rowIterator.hasNext()) {
        Row row = rowIterator.next(); 
        Iterator<Cell> cellIterator = row.cellIterator();
        Listitem li = new Listitem();

        while(cellIterator.hasNext()) {
            Cell cell = cellIterator.next();

            switch(cell.getCellType()) { 
                case Cell.CELL_TYPE_STRING: //handle string columns
                    cell.getStringCellValue();          
                    li.setValue(cell.getStringCellValue());
                    li.appendChild(new Listcell(cell.getStringCellValue()));
                    break;
                case Cell.CELL_TYPE_NUMERIC: //handle double data
                    cell.getNumericCellValue();
                    li.setValue(cell.getNumericCellValue());
                    li.appendChild(new Listcell(String.valueOf(cell.getNumericCellValue())));
                    break;
            }


        }
        list.appendChild(li);
    }

}

我已经通过add external JAR按钮将 poi-3.8,poi-ooxml-3.8,poi-ooxml-schema-3.8,xmlbean-2.3 添加到我的java构建路径库中项目属性。

我有什么想念,所以我得到这个错误吗?请帮帮我,我真的很绝望.. 感谢..

0 个答案:

没有答案