Java - Import Excel with combo and checkbox

1

I need to perform an excel spreadsheet import using java. Only the worksheet has selection values such as checkboxes and combos. As in the example below:

Does anyone have an example java code that can retrieve these values, with Apache poi, JExcel or any other in Java?

    
asked by anonymous 30.10.2017 / 20:46

1 answer

0

Resolution with the Apache POI.

The combobox will be read in the same way as a normal cell. The only detail is in the checkbox reading. This field is a Boolean, configuring it will indicate which cell will receive true / false. You should get the value you want from this cell. In my case, I configured the checkbox as follows:

Thismeansthatregardlessofwherethecheckboxis,whenmarkingoruncheckingit,thevalueofthecheckbox(true/false)willbestoredincellC7.

Excelexample:

Codesample:

publicstaticvoidmain(Stringargs[])throwsIOException{try(InputStreaminputStream=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());
        }
    }
    
28.11.2017 / 02:07