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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM