HSSFSheet hidden = wk.createSheet("hidden"); HSSFCell cell = null; for (int i = 0, length= strs.length; i < length; i++) { String name = strs[i]; HSSFRow row = hidden.createRow(i); cell = row.createCell(0); cell.setCellValue(name); } CellRangeAddressList regions = new CellRangeAddressList(0,0, 0, 0); //獲取單元格的座標 System.out.println(regions.getCellRangeAddress(0).formatAsString()); Name namedCell = wk.createName(); namedCell.setNameName("hidden"); namedCell.setRefersToFormula("hidden!A1:A" + strs.length); //加載數據,將名稱爲hidden的 DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden"); // 設置數據有效性加載在哪一個單元格上,四個參數分別是:起始行、終止行、起始列、終止列 CellRangeAddressList addressList = new CellRangeAddressList(2, 65535, 0, 0); HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint); //將第二個sheet設置爲隱藏 wk.setSheetHidden(1, true); st.addValidationData(validation);