码迷,mamicode.com
首页 > 编程语言 > 详细

java poi excel导入模板设置下拉框

时间:2019-05-09 15:25:20      阅读:1036      评论:0      收藏:0      [点我收藏+]

标签:ons   model   code   []   font   apach   size   下拉   tee   

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导入模板设置下拉框

标签:ons   model   code   []   font   apach   size   下拉   tee   

原文地址:https://www.cnblogs.com/BobXie85/p/10838506.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!