Ok, basically i’m trying to write 3 columns and N number of rows simultaneously while iterating. The problem is that 2 of the 3 columns are written with the values… even though they appear in the System.out.println(), are not being written in the Excel. Here’s the code:
for(int i = 0; i < versionsToGraph.length; i++) {
List<WsCallEntry> wfCalls = allCalls.get(i);
int cant = -1;
if(!wfCalls.isEmpty()) {
for (WsCallEntry wsCallEntry : wfCalls) {
String x = wsCallEntry.getKey();
int y = wsCallEntry.getValue();
cant++;
if(versionsToGraph[i].equals("15.6")) {
System.out.println(x + " " + y + " will be added.");
XSSFSheet sheet = (XSSFSheet) wb.getSheetAt(0);
XSSFRow row = sheet.createRow(27+cant);
XSSFCell celly = row.createCell(10);
celly.setCellValue(y);
}else{
if(versionsToGraph[i].equals("15.9")) {
System.out.println(x + " " + y + " will be added.");
XSSFSheet sheet = (XSSFSheet) wb.getSheetAt(0);
XSSFRow row = sheet.createRow(27+cant);
XSSFCell celly = row.createCell(11);
celly.setCellValue(y);
}
}
xValues.add(x);
}
Collections.sort(xValues, new StringComparator());
}
}
ArrayList<String> newList = eliminarRepetidos(xValues);
int cant = 0;
for (String newlist : newList) {
String x = newlist;
XSSFSheet sheet = (XSSFSheet) wb.getSheetAt(0);
XSSFRow row = sheet.createRow(27+cant);
XSSFCell cellx = row.createCell(9);
cellx.setCellValue(x);
cant++;
}
}
So, it should add in this part of the code, the 15.6, 15.9 Y values, and in the last foreach writes the X values in the Excel.
What i’m getting is X values and 15.9 Y values. What am I not getting the 15.6 ones? 🙁
(from the comment)
I´m using these
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
You are creating the same row on every iteration of
versionsToGraph, you are erasing what was added in previously.You should be doing
after the first iteration.