XSSFWorkbook导出模板下拉菜单设置
package test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.DataValidation;
html下拉菜单的制作方法import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Demo {
public static void main(String[] args) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = ateSheet("Sheet Name");
String[] strs = new String[]{"aa","bb","cc","dd","ee","ff","gg","hh","ii"};
CellRangeAddressList regions = new CellRangeAddressList(0, 9, 0, 0);
DataValidationHelper dataValidationHelper = DataValidationHelper();
DataValidationConstraint createExplicitListConstraint = ateExplicitListConstraint(strs);
DataValidation createValidation = ateValidation(createExplicitListConstraint, regions);
//处理Excel兼容性问题
if (createValidation instanceof XSSFDataValidation) {
createValidation.setSuppressDropDownArrow(true);
createValidation.setShowErrorBox(true);
} else {
createValidation.setSuppressDropDownArrow(false);
}
spreadsheet.addValidationData(createValidation);
FileOutputStream out = new FileOutputStream( new File("D:/Writesheet.xlsx"));
workbook.write(out);
out.close();
}
}
最近⼀个需求要求在导⼊模板上⾯添加下拉菜单,了很多资料都是excel2003版的下拉菜单制作,在这⾥记录⼀下2007版的做法

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。