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错掉了,但是正确的应该怎么写呢?请高手指教一下,不胜感激。
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错掉了,但是正确的应该怎么写呢?请高手指教一下,不胜感激。
解决方案 »
- struts2遇到了一个难以解决的问题
- struts2 tree标签 超链接
- 上网后JSP页面打不开
- Package oracle.jdbc.driver is sealed.高手们帮忙看下,困饶2天的难题!
- jsp中param如何区分form,url,session,cookie等
- [求助]浏览器提示javascript error 但是没有提示
- Connection reset by peer: socket write error 错误如何解决?
- tomcat怎样配置二级域名
- 我想知道利用COOKIE是怎样实现用户登陆后的跟踪问题
- 做字符串比较出错,简单问题,求助
- 急:使用fckeditor中文显示为乱码!
- 请问下高手,怎么才能隐藏url重写后面的参数?
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();}}
你这样写看看。
这些方法都不是static的,用你上边的Sheet对象rs,
都换成 rs.getColumns(); ……
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();
}
}
这是我写的,你可以参照一下
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()不是静态方法,所以不能直接通过类来调用吗?
第三个大概是包没有引入。
<%
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?谢谢各位高手大大指教了
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吧!
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{}%>