Cannot get a STRING value from a NUMERIC cell | Selenium Forum
M
Posted on 22/03/2017
I am trying to read a date from excel using the following code :

package Test01;

import java.io.File;
import java.io.FileInputStream;


import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Class02 {
public static void main(String[]args) throws Exception{
File src=new File ("C:\\Users\\c38151\\Desktop\\test files\\testdata.xlsx");
FileInputStream fi=new FileInputStream (src);
XSSFWorkbook wb=new XSSFWorkbook(fi);
XSSFSheet sheet1=wb.getSheetAt(0);
String v = sheet1.getRow(1).getCell(0).getStringCellValue();

System.out.println("the value is taking from " +v);

}
}


I am having the following error :

"Cannot get a STRING value from a NUMERIC cell"

M
Replied on 22/03/2017

can u please share the code....and also I need to get the data from excel sheet to a field.

Please help


M
Replied on 22/03/2017

convert numeric cell to string.

by using this [color=#FF0000:34jlevaz]'[/color:34jlevaz]

example:
[color=#FF0000:34jlevaz]'1234567[/color:34jlevaz]


M
Replied on 25/03/2017

try this.
cellValueInString = new BigDecimal(cell.getNumericCellValue()).toPlainString();