0

i tried doing this

List<String> values = new ArrayList<>();
values.add("test1");
values.add("test2");
values.add("test3");
values.add("test4");
values.add("test5");

for(String e : values) {
    for (int column = 0; column < 30; column++){
        mGrid.setCellValue(10, column, e);
    }
}

But the only value that is being displayed in the cells is the last value which is "test5".

I also tried displaying the values through the console and it worked fine. Help me plz

Marco R.
  • 2,667
  • 15
  • 33
James Buns
  • 47
  • 8
  • Hey, it is working as expected, what is the expected behaviour? – Dhawal Kapil May 17 '19 at 02:59
  • @DhawalKapil cell 1 = test 1 cell 2 = test 2 something like this but all the cells are just displaying the last item – James Buns May 17 '19 at 03:19
  • ok, why are we iterating from 0 to 30 column, can you upload a snapshot of the sheet that you are expected to be generated from this code. As per the outer for-loop and inner loop, test5 will be written for all the columns 0 to 30 – Dhawal Kapil May 17 '19 at 03:23

1 Answers1

1

You need to iterate the values and columns together with something like, so instead of:

        for(String e : values) {
            for (int column = 0; column < 30; column++){
                mGrid.setCellValue(10, column, e);
            }
        }

use something like:

        for (int column = 0; column < values.length; column++)
            mGrid.setCellValue(10, column, values.get(column));
Marco R.
  • 2,667
  • 15
  • 33