Ir ao conteúdo
  • Cadastre-se

Como colocar os valores do excel em um arraylist em java?


sivio

Posts recomendados

Eu consegui colocar o nome mais eu não estou consegundo colocar o id e a categoria.Como devo fazer para colocar o valor do id e da categoria no comando abaixo?:

"PlanoDeSaude FP1 = new PlanoDeSaude(cell.toString(),cell1.toStr…

package domain;

public class PlanoDeSaude {

int id;

String nome;

Categoria categoria;

public PlanoDeSaude(int id, String nome){

this.id = id;

this.nome = nome;

}

public void setId(int id) {

this.id = id;

}

public int getId() {

return id;

}

public void setNome(String nome) {

this.nome = nome;

}

public String getNome() {

return nome;

}

public void setCategoria(Categoria categoria) {

this.categoria = categoria;

}

public Categoria getCategoria() {

return categoria;

}

}

}

package domain;

public enum Categoria {

A,B,C,D,E;

}

package teste;

import domain.*;

import java.io.IOException;

import java.util.ArrayList;

import org.apache.poi.hssf.usermodel.HSSFRow;

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.util.CellReference;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.CellValue;

import org.apache.poi.ss.usermodel.DateUtil;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Sheet;

import org.apache.poi.ss.usermodel.Workbook;

import org.apache.poi.xssf.usermodel.XSSFWorkbo…

import org.junit.Test;

public class TestePlanoDeSaude {

@Test

public void ler() throws IOException{

Workbook wb =new XSSFWorkbook(getClass().getResourceAsStr…

Sheet sheet1 = wb.getSheetAt(1);

Row row = sheet1.getRow(1);

Cell cell = row.getCell(0);

Row row1 = sheet1.getRow(1);

Cell cell1 = row.getCell(1);

Row row2 = sheet1.getRow(1);

Cell cell2 = row.getCell(2);

PlanoDeSaude FP1 = new PlanoDeSaude(cell.toString(),cell1.toStr…

ArrayList<PlanoDeSaude> lista = new ArrayList<PlanoDeSaude>();

lista.add(FP1);

for(int i = 0;i<lista.size();i++){

System.out.println(lista.get(i).getId())…

System.out.println(lista.get(i).getNome(…

System.out.println(lista.get(i).getCateg…

}

}

}

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!