I have a 13 rows x 31 cell imported from a excel file and then store it inside arraylist so basically it is a 2d array like this
[1,2,3,4,5.................]
[a,b,c,d,e.................]
and then I convert it to String[] array like this
String [] array = null;
for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
Row r = sheet.getRow(rowNum);
ArrayList<String> dl = new ArrayList<String>();
for (int i = 3; i < r.getLastCellNum() + 1; i = i + 3) {
Cell cell = r.getCell(i);
val = formatter.formatCellValue(cell);
dl.add(val);
array = dl.toArray(new String[dl.size()]);
}
// send array as parameter to another method inside the same class
WriteNewFile(array);
break;
}
in another method to create a new excel file, I have to loop the array than contain data like array data above.
for (int x= 0; x<= total - 1; x++) {
Row row3 = sheet.getRow( x+ 2);
Cell cell1 = row3.createCell(3);
cell1.setCellValue(array[x]);
}
when I run this code, I got error message like this:
java.lang.ArrayIndexOutOfBoundsException: 32
the aim of my code is I want to print the array in a single cell and loop the row until total-1.
the value of total is 396
UPDATED
for (int x= 0; x< array.length; x++) {
Row row3 = sheet.getRow( x+ 2);
Cell cell1 = row3.createCell(3);
cell1.setCellValue(array[x]);
}
the looping for the java.lang.ArrayIndexOutOfBoundsException: 32
has been solved.
back to the main question, now I able to print out the first row only
[1,2,3,4,5.................] //of this row
how to continue for the next row? Do I better convert it to 1d array?
UPDATED
now after received the array as the parameter send by other method to writeNewFile method(writeNewFile method only task is to write the new excel file using apache poi of the array data) and I can write the data like this:
|test|
1
2
3
4
5
6
supposedly I want to loop the array to be continue loop for the next row like this
|test|
1
2
3
4
5
6
a
b
b
d
e