Example usage for org.apache.poi.hssf.usermodel HSSFDataValidationHelper createExplicitListConstraint

List of usage examples for org.apache.poi.hssf.usermodel HSSFDataValidationHelper createExplicitListConstraint

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFDataValidationHelper createExplicitListConstraint.

Prototype

public DataValidationConstraint createExplicitListConstraint(String[] listOfValues) 

Source Link

Usage

From source file:com.frameworkset.platform.sanylog.util.POIExcelUtil.java

License:Open Source License

/**
 * 17??17./*from www.j a v  a  2 s.com*/
 * 
 * @param sheet
 * @param dataList
 * @param fieldName
 * @return
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @author gw_liaozh
 */
public static DataValidationConstraint createExplicitListConstraint(HSSFSheet sheet, List<?> dataList,
        String fieldName) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {//
    HSSFDataValidationHelper dvHelper = new HSSFDataValidationHelper(sheet);
    List<String> strList = new ArrayList<String>();
    for (Object obj : dataList) {
        Object value = BeanConvertUtil.getProperty(obj, fieldName);
        //ClassInfo classInfo = ClassUtil.getClassInfo(obj.getClass());
        //Object value = classInfo.getPropertyDescriptor(fieldName).getValue(obj);
        if (value != null) {
            strList.add(value.toString());
        }
    }
    return dvHelper.createExplicitListConstraint(strList.toArray(new String[strList.size()]));
}