1
Hi, I’m having a problem to popular a table the way I need, I want to do something like this.
But with my code I can only get people like this.
How do I format the same way? I tried to skip the lines to do similar but I can’t.
public void exportar() throws IOException {
    ArrayList<Dados> array = listaDados;
    String fileName = "C:/novo.xlsx";
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheetEtiquetas = workbook.createSheet("Etiquetas");
    int rownum = 0;
    for (Dados dados : array) {
        Row row = sheetEtiquetas.createRow(rownum++);
        int cellnum = 0;
        Cell cellOp = row.createCell(cellnum++);
        cellOp.setCellValue("Número O.P: " + dados.getNumeroOP());
        Cell cellNomeItem = row.createCell(cellnum++);
        cellNomeItem.setCellValue("Código da Peça: " + dados.getNomeItem());
        Cell cellPedido = row.createCell(cellnum++);
        cellPedido.setCellValue("Número do Pedido: " + dados.getNumeroPedido());
        Cell cellCliente = row.createCell(cellnum++);
        cellCliente.setCellValue("Cliente: " + dados.getCliente());
        Cell cellQuantidade = row.createCell(cellnum++);
        cellQuantidade.setCellValue("Quantidade: " + dados.getQuantidade());
        rownum++;
    }
    try {
        FileOutputStream out
                = new FileOutputStream(new File(fileName));
        workbook.write(out);
        out.close();
        System.out.println("Arquivo Excel criado com sucesso!");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.out.println("Arquivo não encontrado!");
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("Erro na edição do arquivo!");
    }
Thank you.



Fantastic, it worked perfectly! Thank you very much, know how I can put the edge and set the size of Cell?
– Alan Santos
If it worked, mark the answer as accepted, to make life easier in future research! Regarding the border, you can check this link: https://stackoverflow.com/questions/5720049/add-borders-to-cells-in-poi-generated-excel-file
– Pedro
I’ve already scored the answer, but I don’t have enough reputation yet to show up, but I said it was accounted for! Thanks!
– Alan Santos