Java设置Excel有效性

XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("Excel");
String[] textlist = {"a","b","c"};
//设置Excel数据有效性
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper
.createExplicitListConstraint(textlist);
CellRangeAddressList addressList = null;
XSSFDataValidation validation = null;
//四个参数分别是:起始行、终止行、起始列、终止列
addressList = new CellRangeAddressList(3, 200, 4, 4);
validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
//数据有效性对象
sheet.addValidationData(validation);
String fileStr = "Table.xls";
ExcelUtil.writer(wb, fileStr); String resPath = AliyunOssClient
.uploadFile(AliyunOssClient.mobileQrcode + "Excel" + "/dishT.xls", new File(fileStr));
return resPath;
上一篇:从 JavaScript 到 TypeScript


下一篇:Docker系列之(一):10分钟玩转Docker