java poi excel导入模板设置下拉框
Posted bobxie85
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java poi excel导入模板设置下拉框相关的知识,希望对你有一定的参考价值。
import org.apache.poi.hssf.usermodel.DVConstraint; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataValidation; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; // 初始一个workbook HSSFWorkbook workbook = new HSSFWorkbook(); // 创建一个sheet HSSFSheet sheet= workbook.createSheet(); // 创建行 HSSFRow row= sheet.createRow(0); // 创建列 HSSFCell cell= row.createCell(index++); // 准备下拉列表数据 List<BasicDBObject> options = (List<BasicDBObject>) bo.get("options"); String[] optionArr = new String[options.size()]; for (int i = 0; i < options.size(); i++) { optionArr[i] = options.get(i).getString("value"); } // 设置第一列的1-10000行为下拉列表 CellRangeAddressList regions = new CellRangeAddressList(0, 10000, 0, 0); // 创建下拉列表数据 DVConstraint constraint = DVConstraint.createExplicitListConstraint(optionArr); // 绑定 HSSFDataValidation dataValidation = new HSSFDataValidation(regions, constraint); sheet.addValidationData(dataValidation);
以上是关于java poi excel导入模板设置下拉框的主要内容,如果未能解决你的问题,请参考以下文章