如何获得从Excel的整数值到Java

我导入了Apache.POI包,并希望从Excel单元格获得整数值到Java控制台。 我知道如何获得从Excel单元格到Java控制台的string值

System.out.println(sh1.getRow(0).getCell(2).getRichStringCellValue().toString()); 

但我不知道如何获得整数值。 请帮帮我。

代码如下。

 import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.util.WorkbookUtil; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Cell; public class Excel { public static void main(String[] arg){ Workbook workbook = new HSSFWorkbook(); Sheet sh1 = workbook.createSheet("sheet1"); Cell cell1 = sh1.createRow(0).createCell(0); Cell cell2 = sh1.createRow(0).createCell(1); Cell cell3 = sh1.createRow(0).createCell(2); cell1.setCellValue(100); cell2.setCellValue(200); cell3.setCellFormula("A1+B1"); //Here!! I want to get integer value of cell3 System.out.println(sh1.getRow(0).getCell(2).....); .......... } } 

谢谢

使用函数getNumericCellValue() 。 有关更多信息,请参阅HSSFCell的文档。