0

I need to create a dynamic array with data from a Excel spreadsheet using Apache-POI and Selenium.

My goal is to be able to create a dynamic array with 2 data types(int and String's)to be called to be inputted into a text field using Selenium WebDriver. I have already gotten the information to be hardcoded, however I'd like to be able to not rely on the workbook to increase the speed of my program.

General structure:

for(int i = 0; i < sheet1.getLastRowNum(); i++) { string cell[i] = formatter.formatCellValue(sheet1.getRow(i).getCell(0) }

The errors I get are, "Syntax Error on token "i", delete this token" and also "Type mismatch: Cannot convert from "String" to "String[]"

gotj
  • 39
  • 1
  • 8

1 Answers1

0

Would it work if you stored everything in the array as a string? You could just use String.valueOf() to convert the cell value to a string, and if you need to get it back later on as an int you could use Integer.parseInt().

You can make an array of Objects, but that could cause more trouble than it's worth. You could be adding an object into it which has a type you never accounted for, which could cause you problems later on down the line.

Alex
  • 642
  • 1
  • 9
  • 23
  • Well that's where the 'formatter.formatCellValue(sheet1.getRow(i).getCell(0)' comes into play, if I use any type of data is should just be allowed to be entered into the text field. If I do the array of Objects if there is a type I didn't account for the formatter would just make it into something that will essentially become a string. – gotj Jul 14 '17 at 15:27
  • Ah, OK. I didn't know what it did exactly. I assumed that it just parsed the value into the appropriate format (string, int, double, datetime, etc). – Alex Jul 14 '17 at 16:01