I have an application and I can pass the data quietly to excel, the problem has arisen now because I have to make a loop and I can not find the best way to do this. I have several lots, for example 1,2,3,4,5,6,7,8. Each lot has several customers, we assume that lot 1 has 2 customers, and lot 2 has 4 customers. What I basically want to do is list it like this:
Numero do lote 1:
Diego
Bruno
Numero do lote 2:
Rafael
Carlos
Ana
Tiago
I'm doing the loop like this, but it always repeats all in all excel cells, and it looks like this:
Numero do lote 1:
Rafael
Carlos
Ana
Tiago
Numero do lote 2:
Rafael
Carlos
Ana
Tiago
This is the code:
int cont2 = 0;
//Laço que pega o numero do lote e sempre o repete após os clientes
for (int r = 0; r < listaGuia.size(); r++) {
XSSFRow cabRowAnaliticor = sheet1.createRow((cont2 * 1) + 7);
for (int x = 0; x <= 11; x++) {
cabRowAnaliticor.createCell(x);
}
XSSFCell cellAnaR = cabRowAnaliticor.getCell(0);
cellAnaR.setCellStyle(estiloS2);
cellAnaR.setCellValue(listaGuia.get(r).getNumeroLote());
//Percorre a lista e preenche as celulas
for (int i = 0; i < listaGuia.size(); i++) {
XSSFRow cabRowAnalitico7 = sheet1.createRow((cont2 * 1) + 8);
for (int x = 0; x <= 11; x++) {
cabRowAnalitico7.createCell(x);
}
System.err.println("Lote no rel: " + listaGuia.get(i).getNumeroLote());
XSSFCell cellAnaA5 = cabRowAnalitico7.getCell(0);
cellAnaA5.setCellStyle(estiloS2);
cellAnaA5.setCellValue(listaGuia.get(i).getNumeroGuia());
XSSFCell cellAnaB5 = cabRowAnalitico7.getCell(1);
cellAnaB5.setCellStyle(estiloS2);
cellAnaB5.setCellValue(listaGuia.get(i).getNumeroCarteira());
XSSFCell cellAnaC5 = cabRowAnalitico7.getCell(2);
cellAnaC5.setCellStyle(estiloS2);
cellAnaC5.setCellValue(listaGuia.get(i).getNomeBeneficiario());
XSSFCell cellAnaD5 = cabRowAnalitico7.getCell(3);
cellAnaD5.setCellStyle(estiloS2);
cellAnaD5.setCellValue(listaGuia.get(i).getDataRealizacao());
XSSFCell cellAnaE5 = cabRowAnalitico7.getCell(4);
cellAnaE5.setCellStyle(estiloS2);
cellAnaE5.setCellValue(listaGuia.get(i).getCodServico());
XSSFCell cellAnaF5 = cabRowAnalitico7.getCell(5);
cellAnaF5.setCellStyle(estiloS2);
cellAnaF5.setCellValue("Outras Tabelas");
XSSFCell cellAnaG5 = cabRowAnalitico7.getCell(6);
cellAnaG5.setCellStyle(estiloS2);
cellAnaG5.setCellValue(listaGuia.get(i).getDescServico());
XSSFCell cellAnaH5 = cabRowAnalitico7.getCell(7);
cellAnaH5.setCellStyle(estiloS2);
cellAnaH5.setCellValue(listaGuia.get(i).getQtdExec());
XSSFCell cellAnaI5 = cabRowAnalitico7.getCell(8);
cellAnaI5.setCellStyle(estiloS1);
cellAnaI5.setCellValue(listaGuia.get(i).getFilme());
XSSFCell cellAnaJ5 = cabRowAnalitico7.getCell(9);
cellAnaJ5.setCellStyle(estiloS1);
cellAnaJ5.setCellValue(listaGuia.get(i).getValorServico());
XSSFCell cellAnaK5 = cabRowAnalitico7.getCell(10);
cellAnaK5.setCellStyle(estiloS1);
cellAnaK5.setCellValue(listaGuia.get(i).getHonorario());
if (listaGuia.get(i).getTipoGlosa() != null) {
XSSFCell cellAnaL5 = cabRowAnalitico7.getCell(11);
cellAnaL5.setCellStyle(estiloS1);
float xxx = 0f;
cellAnaL5.setCellValue(xxx);
} else {
XSSFCell cellAnaL5 = cabRowAnalitico7.getCell(11);
cellAnaL5.setCellStyle(estiloS1);
cellAnaL5.setCellValue(listaGuia.get(i).getValor());
}
cont2++;
}
}