Java 如何读取excel单元格值中的下拉列表项?

Java 如何读取excel单元格值中的下拉列表项?,java,excel,apache-poi,Java,Excel,Apache Poi,我已在同一单元格中保存了相同类型的联系人详细信息(例如,此人有多个电子邮件地址)。我已在一个单元格中将其保存为列表,但在遍历excel工作表时无法读取。我只能读取当前选择/显示的选项,其他选项将被忽略。我在用java //Read sheet inside the workbook by its name Sheet _workSheet = _workbook.getSheet(sheetName); //Iterate through each rows Iterator<Row&

我已在同一单元格中保存了相同类型的联系人详细信息(例如,此人有多个电子邮件地址)。我已在一个单元格中将其保存为列表,但在遍历excel工作表时无法读取。我只能读取当前选择/显示的选项,其他选项将被忽略。我在用java

//Read sheet inside the workbook by its name

Sheet _workSheet = _workbook.getSheet(sheetName);

//Iterate through each rows
Iterator<Row> rowIterator = _workSheet.iterator();

while(rowIterator.hasNext())
{
    //Get Each Row
    Row row_ = rowIterator.next();

    //Iterator through each column of each row
    Iterator<Cell> cellIterator = row_.cellIterator();

    while(cellIterator.hasNext())
    {
        Cell cell = cellIterator.next();                         

        //Checking the cell format
        switch(cell.getCellType())
        {
            case Cell.CELL_TYPE_NUMERIC:
                System.out.println(cell.getNumericCellValue()+"\n");
                break;

            case Cell.CELL_TYPE_STRING:
                System.out.println(cell.getStringCellValue()+"\n");
                break;

            case Cell.CELL_TYPE_BOOLEAN:
                System.out.println(cell.getBooleanCellValue()+"\n");
                break;

            case Cell.CELL_TYPE_BLANK:
                System.err.println(cell.getStringCellValue()+" .....empty cell");
                break;
        }
    }
    System.err.println("");

}
//根据工作簿中的工作表名称读取工作表
工作表=工作簿.getSheet(sheetName);
//遍历每一行
迭代器行迭代器=_工作表.迭代器();
while(roweiterator.hasNext())
{
//拿到每一行
行=行迭代器.next();
//遍历每行的每列的迭代器
迭代器cellIterator=行\单元格迭代器();
while(cellIterator.hasNext())
{
Cell=cellIterator.next();
//检查单元格格式
开关(cell.getCellType())
{
case Cell.Cell\u类型\u数值:
System.out.println(cell.getNumericCellValue()+“\n”);
打破
case Cell.Cell\u类型\u字符串:
System.out.println(cell.getStringCellValue()+“\n”);
打破
case Cell.Cell\u类型\u布尔值:
System.out.println(cell.getBooleanCellValue()+“\n”);
打破
case Cell.Cell\u类型\u空白:
System.err.println(cell.getStringCellValue()+“…空单元格”);
打破
}
}
System.err.println(“”);
}
在单元格“A2”中,我希望得到两个值(emailone,emailTwo)

这些值成功了;
List dataValidations=sheet.getDataValidations();
迭代器迭代器=dataValidations.Iterator();
XSSFDataValidation=iterator.next();
String[]explicitListValues=dataValidation.getValidationConstraint().getExplicitListValues();

您指的是一个单元格中的哪种列表?这是一个数据验证列表吗?可能是重复的谢谢,这些都成功了。List dataValidations=sheet.getDataValidations();迭代器迭代器=dataValidations.Iterator();XSSFDataValidation=iterator.next();String[]explicitListValues=dataValidation.getValidationConstraint().getExplicitListValues();
These did the trick;
List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
            Iterator<XSSFDataValidation> iterator = dataValidations.iterator();
            XSSFDataValidation dataValidation = iterator.next();
            String[] explicitListValues = dataValidation.getValidationConstraint().getExplicitListValues();