本文介绍了使用Apache POI Excel的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建使用Apache POI的下拉列表中的Excel文件。而我能做到这一点,以便但是
我不能够使下拉列表中的默认项目第一个项目。

公共类SD {/ **
 * @参数ARGS
 *引发IOException
 * /
公共静态无效的主要(字串[] args)抛出IOExceptionDataValidation dataValidation = NULL;
DataValidationConstraint约束= NULL;
DataValidationHelper validationHelper = NULL; XSSFWorkbook WB =新XSSFWorkbook();
 XSSFSheet工作表Sheet1 =(XSSFSheet)wb.createSheet(工作表Sheet1);
    validationHelper =新XSSFDataValidationHelper(Sheet1中);
    CellRangeAddressList AddressList中=新CellRangeAddressList(0,5,0,0);
    约束= validationHelper.createExplicitListConstraint(新的String [] {SELECT,10,20,30});
    dataValidation = validationHelper.createValidation(约束,AddressList中);
    dataValidation.setSup pressDropDownArrow(真);
    sheet1.addValidationData(dataValidation);    FileOutputStream中FILEOUT =新的FileOutputStream(C:\\\\ \\\\温度vineet.xlsx);
    wb.write(FILEOUT);
    fileOut.close();
}}


解决方案

设置默认值,只是setCellValue(first_item_value);

  sheet.getRow(1).getCell(指数).setCellValue(my_default_value);

我已经做到了为面临同样的问题。

I need to create a drop down list in excel file using Apache POI. and I am able to do that so ButI am not able to make first item in drop down list as default Item.

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();
}

}
解决方案

to set a default value, just setCellValue("first_item_value");

sheet.getRow(1).getCell(index).setCellValue("my_default_value");

I have did it as facing the same problem.

这篇关于使用Apache POI Excel的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 16:09