0

Hi I am trying to read excel data at the time of execution.Before I was sending all data as a string in excel sheet and my code was working fine but after some change i need to read one numeric column also using same code . But i am getting error

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;
    }

Can any one help me i want to read complete excel data . I have total 6 sheets and in every sheet i have multiple data in row and column . Unable to read numeric data from excel sheet.

Tarun Dabbs
  • 67
  • 13
  • See https://stackoverflow.com/questions/10616935/reading-date-value-from-excel-cell-as-a-string – mentallurg May 21 '18 at 11:32
  • @Gagravarr In this link if(cellCount == TEMPLATE_PASSWORD) coloum name is hardcoded but it can be change at client location . I am looking a like if anyone update excel sheet like update coloum name , add numeric value . same code should be worked . I am also storing all values in array . Can you please suggest me solution as per my code – Tarun Dabbs May 21 '18 at 11:45

0 Answers0