poi 下拉框实现

  需要导入jar包

 


import
java.io.FileOutputStream; import org.apache.poi.ss.usermodel.DataValidation; import org.apache.poi.ss.usermodel.DataValidationConstraint; import org.apache.poi.ss.usermodel.DataValidationHelper; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook;

  /**
   * 思路:
   * 1.工作簿
   * 2.下拉框位置
   * 3.下拉框数据
   * @param filePath
   * @throws Exception
   */

public class ExcelTest {
    public static void main(String[] args) {
        try 
        {
            dropDownList42007("E:\\test.xlsx");
        } 
        catch (Exception e) {

            e.printStackTrace();
        }
    }


/**
public static void dropDownList42007(String filePath) throws Exception { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("test"); String [] subjects = new String []{"JAVA","C++","JS"}; DataValidationHelper helper = sheet.getDataValidationHelper(); DataValidationConstraint constraint = helper.createExplicitListConstraint(subjects); CellRangeAddressList addressList = null; DataValidation dataValidation = null; for (int i = 0; i < 100; i++) { addressList = new CellRangeAddressList(i, i, 0, 0); dataValidation = helper.createValidation(constraint, addressList); sheet.addValidationData(dataValidation); } FileOutputStream stream = new FileOutputStream(filePath); workbook.write(stream); stream.close(); addressList = null; dataValidation = null; } }

 

转载于:https://www.cnblogs.com/person008/p/9395531.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值