2017-03-14 54 views
-2
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);  
    } 
} 
}   

,我发现了以下错误的RuntimeException:“不可编译的源代码 - 错误的符号型” 使用Apache POI

run: 
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: jxl.Cell.setCellType 
    at readexcel.ReadExcel.main(ReadExcel.java:32) 
+4

是否被包含在类路径上你的依赖?这段代码是否看起来破损(可能由您的IDE标记)? –

回答

0

看起来使用Apache POI。请包括所有在类路径

+1

它们在我的类路径中,代码没有使用c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);但我需要它来处理这个问题,因为我想为单元格写一条if语句。当我写来的时候(c = 8)它说c是类型单元格而8是int。 – justaskingforproject

+1

按照https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Cell.html CELL_TYPE_NUMERIC看起来不推荐使用。尝试以下c.setCellType(HSSFCell.CellType.NUMERIC); –

+1

我改变它,但它没有工作和单元格类型加下划线并运行它时 – justaskingforproject

2

你没有提到你的Apache POI库的版本的依赖关系和罐子。但是从你描述的错误来看,它听起来像是> 3.15。

请注意,在Apache POI org.apache.poi.hssf.usermodel.HSSFCell类中的方法setCellType(int cellType)已过时和删除。阅读docs

您需要改为使用方法setCellType(CellType cellType)

更换

c.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

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

+0

我试过这个它仍然没有工作。如果有另一种方法将Cell类型转换为int,那将会很好。单元格类型仍然带有下划线。 – justaskingforproject

+0

或者我可以使用if语句的方式单元格类型 – justaskingforproject

+0

当您尝试我的以上建议时,获得的新错误是什么? – VHS

相关问题