imhyung
imhyung

Reputation: 27

how to get integer value from Ms Excel to java

I imported Apache.POI package and want to get integer value from Excel cell to Java console. I know how get the string value from excel cell to Java console

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

but i don't know how to get integer value. Please help me.

The code is below.

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).....);

        ..........
    }

}

thanks

Upvotes: 0

Views: 3734

Answers (1)

Jens
Jens

Reputation: 69450

Use the function getNumericCellValue(). See the documentation of HSSFCell for more information.

Upvotes: 1

Related Questions