String path="D:\\Data\\Book1.xls";InputStream is = new FileInputStream(path);Workbook wb = Workbook.getWorkbook(is);Sheet rs = wb.getSheet(0);Cell cell = null;   int columnCount=Sheet.getColumns();   
int rowCount=Sheet.getRows();   for (int i = 0; i <rowCount; i++) {   
    for (int j = 0; j <columnCount; j++){   
        cell=sheet.getCell(j, i);      
        if(cell.getType()==CellType.NUMBER){   
            System.out.print(((NumberCell)cell).getValue());   
        }   
        else if(cell.getType()==CellType.DATE){   
            System.out.print(((DateCell)cell).getDate());   
        }   
        else{   
            System.out.print(cell.getContents());   
        }   
运行程序,提示An error occurred at line: 8 in the jsp file: /test/test3.jsp
Generated servlet error:
Cannot make a static reference to the non-static method getColumns() from the type SheetAn error occurred at line: 8 in the jsp file: /test/test3.jsp
Generated servlet error:
Cannot make a static reference to the non-static method getRows() from the type SheetAn error occurred at line: 8 in the jsp file: /test/test3.jsp
Generated servlet error:
sheet cannot be resolved应该是getColumns的method错掉了,但是正确的应该怎么写呢?请高手指教一下,不胜感激。

解决方案 »

  1.   

    尝试把getColumns和getRows换成具体数字,getCells又报错。应该怎么解决啊?高手帮帮忙啊。。谢谢
      

  2.   

    jxl.Workbook rwb = Workbook.getWorkbook(stream);
    jxl.Sheet sh = rwb.getSheet(0);
    int rowCount = sh.getRows();
    for(int i=0;i<rowCounts;i++){
    jxl.Cell[] ce = sh.getRow(i);
    for(int j=0;j<ce.length;j++){
     String value=ce[i].getContents().toString();}}
    你这样写看看。
      

  3.   

    Sheet.getColumns();Sheet.getRows();sheet.getCell(j, i); 
    这些方法都不是static的,用你上边的Sheet对象rs,
    都换成   rs.getColumns(); ……
      

  4.   

    public class ReadExl {
    public static void main(String args[])
        {
    String path="c:\\测试数据2.xls";//Excel文件URL
    try{
    InputStream is = new FileInputStream(path);//写入到FileInputStream 
    jxl.Workbook wb = Workbook.getWorkbook(is); //得到工作薄
     jxl.Sheet st = wb.getSheet(0);//得到工作薄中的第一个工作表
     //Cell cell=st.getCell(1,1);//得到工作表的第一个单元格,即A1 
     //String content=cell.getContents();//getContents()将Cell中的字符转为字符串 
     int  row=st.getRows();
     int col=st.getColumns();
     for(int i=1;i<row;i++){
     for(int j=0;j<col;j++){
     Cell cell0 = st.getCell(j, i);//得到工作表的第一个单元格,即A1 
                             String content0 = cell0.getContents();
       }
     }
     
     wb.close();//关闭工作薄
     is.close();//关闭输入流
    }catch(FileNotFoundException e){
    e.printStackTrace();
    }catch(IOException e){
           e.printStackTrace();
          }catch(BiffException e){
           e.printStackTrace();
          }
        }
    这是我写的,你可以参照一下
      

  5.   

    An error occurred at line: 8 in the jsp file: /test/test3.jsp 
    Generated servlet error: 
    Cannot make a static reference to the non-static method getColumns() from the type Sheet An error occurred at line: 8 in the jsp file: /test/test3.jsp 
    Generated servlet error: 
    Cannot make a static reference to the non-static method getRows() from the type Sheet An error occurred at line: 8 in the jsp file: /test/test3.jsp 
    Generated servlet error: 
    sheet cannot be resolved 晕,第一个和第二个问题不是说getColumns()和getRows()不是静态方法,所以不能直接通过类来调用吗?
    第三个大概是包没有引入。
      

  6.   

    请问5楼高手,这个问题静态方法的问题应该怎么解决呢?我看得懂问题,但不知道怎么解决。。请问3楼高手,我的代码已经换成如下:
    <%
    try{ResultSet rs;
    ResultSet rs1;String path="D:\\Data\\Book1.xls";InputStream is = new FileInputStream(path);Workbook wb = Workbook.getWorkbook(is);Sheet rs1 = wb.getSheet(0);Cell cell = null;   int columnCount=rs.getColumns();   
    int rowCount=rs.getRows();   for (int i = 0; i <rowCount; i++) {   
        for (int j = 0; j <columnCount; j++){   
            cell=rs.getCell(j, i);      
            if(cell.getType()==CellType.NUMBER){   
                System.out.print(((NumberCell)cell).getValue());   
            }   
            else if(cell.getType()==CellType.DATE){   
                System.out.print(((DateCell)cell).getDate());   
            }   
            else{   
                System.out.print(cell.getContents());   
            }   
    }
    }
    rs.close();
    rs = null;
    }
    finally{}%>现在的错误是
    An error occurred at line: 8 in the jsp file: /test/test3.jsp
    Generated servlet error:
    ResultSet cannot be resolved to a typeAn error occurred at line: 8 in the jsp file: /test/test3.jsp
    Generated servlet error:
    ResultSet cannot be resolved to a typeAn error occurred at line: 8 in the jsp file: /test/test3.jsp
    Generated servlet error:
    Duplicate local variable rs1应该是ResultSet declare 错误了。。还有rs1重复使用,但是应该怎么问题呢? 如果是写成rs.getColumns()..
    rs要怎么declare?谢谢各位高手大大指教了
      

  7.   

    三楼的是正解.开始,是因为 你从SHEET对象中调用GETROWNS(),这是一个静态方法的写法,而使用的方法是非静态的.所以会报在非静态方法引用了一个静态的方法.
    Sheet   rs   =   wb.getSheet(0); Cell   cell   =   null;       int   columnCount=Sheet.getColumns();     //这个SHEET应该换成RS.然而你在七楼的代码是因为在同一个方法内不同类型的对象都使用了同一个变量名.
    ResultSet   rs; 
    ResultSet   rs1; //此处是JAVA.SQL.RESLUTSETString   path= "D:\\Data\\Book1.xls "; InputStream   is   =   new   FileInputStream(path); Workbook   wb   =   Workbook.getWorkbook(is); Sheet   rs1   =   wb.getSheet(0); //而此处是SHEET.
    把变量换一下,另外导入所要的包,就没有问题了.看你出的错,好像是刚学JAVA吧!
      

  8.   

    最后的问题,请各位大大帮忙。。不胜感激。。代码如下,运行以后发现没有报错,可是也没有内容显示出来,整个IE浏览器是白板这是什么原因造成的啊?我明明excel里面有内容的啊。。PS:怎么给大家加分数啊?谢谢帮忙了。。<%
    try{
    String path="D:\\Data\\Book1.xls";InputStream is = new FileInputStream(path);Workbook wb = Workbook.getWorkbook(is);Sheet rs = wb.getSheet(0);Cell cell = null;   int columnCount=rs.getColumns();   
    int rowCount=rs.getRows();   for (int i = 0; i <rowCount; i++) {   
        for (int j = 0; j <columnCount; j++){   
            cell=rs.getCell(j, i);      
            if(cell.getType()==CellType.NUMBER){   
                System.out.print(((NumberCell)cell).getValue());   
            }   
            else if(cell.getType()==CellType.DATE){   
                System.out.print(((DateCell)cell).getDate());   
            }   
            else{   
                System.out.print(cell.getContents());   
            }   
    }
    }
    rs = null;
    }
    finally{}%>
      

  9.   

    jxl的java包已经放到\webapps\ROOT\WEB-INF\lib下面了啊