Привет, я пытаюсь прочитать данные Excel во время выполнения. Раньше я отправлял все данные в виде строки в листе Excel, и мой код работал нормально, но после некоторых изменений мне нужно прочитать один числовой столбец, также используя тот же код. Но я получаю ошибку
java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell
at org.apache.poi.xssf.usermodel.XSSFCell.typeMismatch(XSSFCell.java:1062)
at org.apache.poi.xssf.usermodel.XSSFCell.getRichStringCellValue(XSSFCell.java:395)
at org.apache.poi.xssf.usermodel.XSSFCell.getStringCellValue(XSSFCell.java:347)
This is my code .
public String[][] readFileAndExcelData(String sheetName) {
int maxLAs = 1000;
int maxRegs = 1000;
String listUsers[][] = new String[maxLAs+1][9];
try {
//-Load the properties
System.out.println("\n" + "---------------------------------------------------------------------------------"+ "\r\n");
System.out.println("Read in PROPERTIES file"+ "\r\n");
System.out.println("---------------------------------------------------------------------------------"+ "\r\n");
Properties prop = new Properties();
InputStream input = null;
String inputFS = getAutomationInputDataPath()+"//Validation.properties";
input = new FileInputStream(inputFS);
prop.load(input);
//-Input file with test data
String userAuthenticationFile = prop.getProperty("users_test_file");
System.out.println("\t" + "userAuthenticationFile = " + userAuthenticationFile + "\r\n");
//-Load the path of the resources folder, containing files to be tested
String resourcesPath = getAutomationInputDataPath()+"/";
System.out.println("\t" + "resourcesPath = " + resourcesPath + "\r\n");
System.out.println("\n" + "---------------------------------------------------------------------------------"+ "\r\n");
System.out.println("Read in INPUT file describing 051 User Authentication"+ "\r\n");
System.out.println("---------------------------------------------------------------------------------"+ "\r\n");
String inputDataFS = resourcesPath + userAuthenticationFile;
InputStream inputData = null;
inputData = new FileInputStream(inputDataFS);
Workbook workbook = new XSSFWorkbook(inputData);
Sheet lasSheet = workbook.getSheet(sheetName);
Iterator<Row> rowIterator = lasSheet.iterator();
//-Maximum maxLAs learning activities may be specified, at this time
//-First row must contain labels
int numberUserAuthentication = 0;
int r = 0;
int c = 0;
while (rowIterator.hasNext()) {
Row nextRow = rowIterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
listUsers[r][c] =cell.getStringCellValue();
c = c + 1;
}
r = r + 1;
c = 0;
}
workbook.close();
inputData.close();
numberUserAuthentication = r-1;
System.out.println("\t" + "Completed reading Excel file that describes User Authentication list. # LAs = " + numberUserAuthentication + "\r\n");
}catch (Exception e) {
e.printStackTrace();
}
return listUsers;
}
Может ли кто-нибудь помочь мне, я хочу прочитать полные данные Excel. У меня всего 6 листов, и на каждом листе у меня есть несколько данных в строке и столбце. Невозможно прочитать числовые данные из таблицы Excel.
@Gagravarr В этой ссылке, если (cellCount == TEMPLATE_PASSWORD) имя столбца жестко задано, но его можно изменить на месте клиента. Я выгляжу так, как если бы кто-нибудь обновлял лист Excel, например, обновлял имя столбца, добавлял числовое значение. тот же код должен работать. Я также храню все значения в массиве. Не могли бы вы предложить мне решение в соответствии с моим кодом




См. stackoverflow.com/questions/10616935/…