Java - Import Excel with combo and checkbox

Asked

Viewed 153 times

1

I need to import an excel spreadsheet using java. Only the spreadsheet has selection values like checkbox lists and combos. As in the example below:

inserir a descrição da imagem aqui

Someone has an example of java code that can retrieve these values, with Apache poi, Jexcel or any other in Java?

1 answer

0


Resolution with Apache POI.

The reading of the combobox will be done in the same way as a normal cell. The only detail is the reading of the checkbox. This field is a boolean, when configuring it you will indicate which cell will receive true/false. You should take the value you want from that cell. In my case, I set up the checkbox as follows:

inserir a descrição da imagem aqui

This means that regardless of where the checkbox is, when you mark or uncheck it, the checkbox value (true/false) will be stored in cell C7.

Excel example:

inserir a descrição da imagem aqui

Code example:

public static void main(String args[]) throws IOException {
        try (
            InputStream inputStream = ReadExcelControls.class.getResourceAsStream("readControls.xls");
            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        ) {
            Sheet sheet = workbook.getSheet("teste");
            Cell nomeComum = sheet.getRow(0).getCell(1);
            Cell classificacaoEspecie = sheet.getRow(2).getCell(1);
            Cell envenenamento = sheet.getRow(6).getCell(2);

            //Campo normal
            System.out.println("Nome Comum: " + nomeComum.getStringCellValue());
            //Combobox
            System.out.println("Classificação Espécie: " + classificacaoEspecie.getStringCellValue());
            //Checkbox
            System.out.println("Evenenamento: " + envenenamento.getBooleanCellValue());
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.