简体   繁体   English

收到此错误:消息:java.lang.IllegalStateException:无法从数字单元格获取文本值

[英]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.

相关问题 java.lang.IllegalStateException:无法从文本单元格获取数值 - java.lang.IllegalStateException: Cannot get a numeric value from a text cell 线程“主”java.lang.IllegalStateException 中的异常:无法从数字单元格中获取文本值 - Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric cell java.lang.IllegalStateException:无法从数字公式单元格获取文本值 - java.lang.IllegalStateException: Cannot get a text value from a numeric formula cell java.lang.IllegalStateException:将Excel工作表上传到服务器时,无法从文本单元格异常中获取数值 - java.lang.IllegalStateException: Cannot get a numeric value from a text cell Exception while uploading excel sheet to server java.lang.IllegalStateException错误消息 - java.lang.IllegalStateException error message 获取错误java.lang.IllegalStateException:从行0 col -1获取字段插槽失败 - Getting Error java.lang.IllegalStateException: get field slot from row 0 col -1 failed java.lang.IllegalStateException错误 - java.lang.IllegalStateException error 获取 java.lang.IllegalStateException: Logback 配置错误检测到错误 - Getting java.lang.IllegalStateException: Logback configuration error detected error 突然报错java.lang.IllegalStateException: Request cannot be executed; I/O反应器状态:STOPPED - Getting this error out of a sudden java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED 获取异常-java.lang.IllegalStateException:错误:文本块内不允许使用drawImage - Getting exception -java.lang.IllegalStateException: Error: drawImage is not allowed within a text block
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM