简体   繁体   中英

Getting this error: Message: java.lang.IllegalStateException: Cannot get a text value from a numeric cell

import com.itko.lisa.vse.stateful.model.TransientResponse;
import com.itko.lisa.vse.stateful.model.Response;
import com.itko.util.ParameterList;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.lang.String;
import org.apache.log4j.*;
import groovy.util.logging.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

    FileInputStream fileInputStream = new FileInputStream("C:/Softwares/LISA/CBO_CurrentBalance1/Data/BalanceReport.xlsx");  
    //FileInputStream fileInputStream = new FileInputStream("/home/lisa-user/Data/CBOPayment.xlsx");
    XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream)
    XSSFSheet sheet = workbook.getSheet("Sheet1");        
    XSSFRow row;
    XSSFCell cell;
    Iterator rows = sheet.rowIterator();
    while (rows.hasNext()) {
        row = (XSSFRow) rows.next();
        Iterator cells = row.cellIterator();                  
        AccountNumber1  = testExec.getStateObject("AccountNumber1")
        AccountNumber2 = testExec.getStateObject("AccountNumber2")

        if (AccountNumber1 == cells.next().getStringCellValue()) {
           if(cells.hasNext()) {
             Balance = cells.next().getNumericCellValue();                               
             testExec.setStateValue("Balance1", Balance);                      
           }
        }

        if (AccountNumber2 == cells.next().getStringCellValue()) {
            if (cells.hasNext()) {
                Balance = cells.next().getNumericCellValue();                               
                testExec.setStateValue("Balance2", Balance);                   
            }
        } 
    }

you need something like this : don't get confused with the naming convention as this is one of my code. the problem is

  DataFormatter fmt = new DataFormatter(); String _charges = fmt.formatCellValue(sheet.getRow(45).getCell(CellReference.convertColStringToIndex("D"))); 

what you are doing is trying to fetch a numeric value from the sheet whereas it is saved as a String so you need to convert it to String before you can use it. The code i have pasted is not the exact solution but i hope you might get the hint about the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM