[英]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. 我粘贴的代码不是确切的解决方案,但希望您能得到有关该解决方案的提示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.