Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;不可编译源代码-错误的符号类型;使用ApachePOI的运行时异常_Java_Excel_Apache Poi - Fatal编程技术网

Java &引用;不可编译源代码-错误的符号类型;使用ApachePOI的运行时异常

Java &引用;不可编译源代码-错误的符号类型;使用ApachePOI的运行时异常,java,excel,apache-poi,Java,Excel,Apache Poi,看起来您正在使用ApachePOI。请在类路径中包含所有依赖项和JAR,因为您没有提到您的ApachePOI库的版本。但是从您描述的错误来看,它听起来好像大于3.15 请注意,Apache POI类org.Apache.POI.hssf.usermodel.HSSFCell中的方法setCellType(int cellType)已被弃用并删除。读这本书 您需要使用方法setCellType(CellType-CellType) 更换 c.setCellType(HSSFCell.CELL\u

看起来您正在使用ApachePOI。请在类路径中包含所有依赖项和JAR,因为您没有提到您的
ApachePOI
库的版本。但是从您描述的错误来看,它听起来好像大于3.15

请注意,Apache POI类org.Apache.POI.hssf.usermodel.HSSFCell中的方法
setCellType(int cellType)
已被弃用并删除。读这本书

您需要使用方法
setCellType(CellType-CellType)

更换

c.setCellType(HSSFCell.CELL\u TYPE\u NUMERIC)


c.setCellType(org.apache.poi.ss.usermodel.CellType.NUMERIC)

类路径中是否包含依赖项?此代码看起来是否已损坏(可能由IDE标记)?它们位于我的类路径中,代码在没有c.setCellType(HSSFCell.CELL\u TYPE\u NUMERIC)的情况下工作;但我需要它来处理这个问题,因为我想为单元格写一个if语句。当我写if(c=8)时,它说c是cell类型,8是int类型。根据cell类型,NUMERIC看起来不太受欢迎。尝试以下c.setCellType(HSSFCell.CellType.NUMERIC);我更改了它,但它不起作用,cellType加了下划线,它说在运行itI时找不到符号并且仍然出错。我猜测cellType在不同的包中,而尝试c.setCellType(cellType.NUMERIC)并导入org.apache.poi.ss.usermodel.cellType;我试过这样做,它修复了单元格类型,但错误转到了数字。我试过这样做,但仍然不起作用。如果有另一种方法将单元格类型转换为int,那就太好了。单元格类型仍然带下划线。或者我可以在单元格类型上使用if语句。当您尝试我的上述建议时,您遇到了什么新错误?您的意思是我必须使用methode setCellType(CellType CellType)来代替吗?我的意思是
setCellType(CellType CellType)
setCellType的替代方法(int cellType)
在较新版本的POI中已被弃用。您是否阅读了我在回答中共享的链接中的文档?再说一遍,尝试我的建议时遇到的新错误是什么?它很简单,肯定会起作用。
package readexcel;

import java.io.File;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.poi.hssf.usermodel.HSSFCell;

public class ReadExcel {

public static void main(String[] args) throws Exception 
{ 
    File f=new File("C:\\Users\\user1\\Desktop\\203132017.xls");
    Workbook wb=Workbook.getWorkbook(f);

    Sheet s=wb.getSheet(0);
    int row=s.getRows();
    int col=s.getColumns();
    HSSFCell cell;

    for (int j=0;j<200;j++){    
      Cell c=s.getCell(10,j);
      c.getContents();       
      c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);       
    }
}
}