Vin*_*eet 17 excel apache-poi xssf
我需要使用Apache POI在excel文件中创建一个下拉列表.我能够做到这一点但是我无法将下拉列表中的第一项作为默认项目.
public class sd {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
DataValidation dataValidation = null;
DataValidationConstraint constraint = null;
DataValidationHelper validationHelper = null;
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet1=(XSSFSheet) wb.createSheet("sheet1");
validationHelper=new XSSFDataValidationHelper(sheet1);
CellRangeAddressList addressList = new CellRangeAddressList(0,5,0,0);
constraint =validationHelper.createExplicitListConstraint(new String[]{"SELECT","10", "20", "30"});
dataValidation = validationHelper.createValidation(constraint, addressList);
dataValidation.setSuppressDropDownArrow(true);
sheet1.addValidationData(dataValidation);
FileOutputStream fileOut = new FileOutputStream("c:\\temp\\vineet.xlsx");
wb.write(fileOut);
fileOut.close();
}
}
Run Code Online (Sandbox Code Playgroud)
设置默认值,只需setCellValue("first_item_value");
sheet.getRow(1).getCell(index).setCellValue("my_default_value");
Run Code Online (Sandbox Code Playgroud)
面对同样的问题,我已经做到了.
| 归档时间: |
|
| 查看次数: |
26698 次 |
| 最近记录: |