arsenal11
arsenal11

Reputation: 69

Converting type XSSFCell to String java

I'm new to Apache POI and HttpClient, and I'm confused. My program is supposed to get the value from an excel cell, and use that value in the HttpGet request. Here is the method that isn't working:

public String censusIdValue(int rowNumber) throws IOException {
    InputStream ExcelFileToRead = new FileInputStream("/Users/john/Documents/Censusplaces (1).xlsx");
    XSSFWorkbook  wb = new XSSFWorkbook(ExcelFileToRead);
    XSSFWorkbook test = new XSSFWorkbook(); 
    XSSFSheet sheet = wb.getSheetAt(0);
    XSSFRow row; 
    XSSFCell cell;

    String value = wb.getSheetAt(0).getRow(rowNumber).getCell(3); 

   return value;
}

wb.getSheetAt(0).getRow(rowNumber).getCell(3); is type XSSFCell, and I need to convert it to a string. Is this possible or did I go about pulling this value incorrectly?

Upvotes: 0

Views: 4892

Answers (2)

Dnyaneshwar Jaybhay
Dnyaneshwar Jaybhay

Reputation: 11

public void getvalFromEcelSheet(){
    File file= new File("pass here path of directry");
    FileInput input=new FileInput(file);
    XSSFWorkBook book=new XSSFWorkBook(input);
    XSSFSheet sheet=book.getSheet("Sheet1");
    XSSFRow row1=sheet.getRow(1);



XSSFCell cell=row1.getCell(1);
    String value=cell.toString();
    //we got String Value from Excelsheet
  }

Upvotes: 1

arsenal11
arsenal11

Reputation: 69

Simple fix. String value = wb.getSheetAt(0).getRow(rowNumber).getCell(3).getStringCellValue();

Upvotes: 0

Related Questions