1

我是 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);
    }

}

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

有什么我想念的,所以我收到了这个错误吗?请帮助我,我在这里真的很绝望..谢谢..

4

0 回答 0