Как установить ограничение при создании выпадающего списка xlsm с помощью Apache POI - PullRequest
0 голосов
/ 13 февраля 2019

Я пытаюсь добавить выпадающий список для одной ячейки, используя Apache POI.Раскрывающийся список содержит 300 строк.

Я получил выпадающий список, но не открывается .. он показывает только выпадающий символ.

Код:

try{
    String excelFilePath="ApplyTiresBatchUpload.xlsm";
    File f=new File(excelFilePath);
    System.out.println("FILE NAME:"+f.getName());
    System.out.println("FILE PATH:"+f.getCanonicalPath());
    FileInputStream fsIP = new FileInputStream(f);
    XSSFWorkbook wb = new XSSFWorkbook(fsIP);
    XSSFSheet worksheet = wb.getSheetAt(0);
    String[] exlist = new String[]{"1LI","1LO","1RI","1RO","2LI","2LO","2RI","2RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","1LI","1LO","1RI","1RO","2LI","2LO","2RI","2RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","1LI","1LO","1RI","1RO","2LI","2LO","2RI","2RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","1LI","1LO","1RI","1RO","2LI","2LO","2RI","2RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","1LI","1LO","1RI","1RO","2LI","2LO","2RI","2RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO","3LI","3LO","3RI","3RO","4LI","4LO","4RI","4RO","5LI","5LO","5RI","5RO"};        
    System.out.println("exlist:-"+exlist.length);
    DataValidationHelper dataValidationHelper = worksheet.getDataValidationHelper();
    CellRangeAddressList  addressList = new  CellRangeAddressList(1, 20, 0, 0);
    DataValidationConstraint dataValidationConstraint =dataValidationHelper.createFormulaListConstraint("hidden!$A$1:$A$" + exlist.length);
    DataValidation dv = dataValidationHelper.createValidation(dataValidationConstraint, addressList);
    dv.setSuppressDropDownArrow(true);
   wb.setSheetHidden(1, true);      
   worksheet.addValidationData(dv);       
   response.setContentType("text/xlsm");
    response.addHeader("Content-Disposition", "attachment; filename=ApplyTiresBatchUpload.xlsm");
    ServletOutputStream outt = response.getOutputStream();
        wb.write(outt);
        outt.flush();
        outt.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch(Exception e){
    e.printStackTrace();
}
...