org.apache.poi.hssf.usermodel.HSSFSheet.addValidationData()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中org.apache.poi.hssf.usermodel.HSSFSheet.addValidationData()方法的一些代码示例,展示了HSSFSheet.addValidationData()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFSheet.addValidationData()方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFSheet
类名称:HSSFSheet
方法名:addValidationData

HSSFSheet.addValidationData介绍

[英]Creates a data validation object
[中]创建数据验证对象

代码示例

代码示例来源:origin: stackoverflow.com

  1. HSSFWorkbook workbook = new HSSFWorkbook();
  2. HSSFSheet realSheet = workbook.createSheet("Sheet xls");
  3. HSSFSheet hidden = workbook.createSheet("hidden");
  4. for (int i = 0, length= countryName.length; i < length; i++) {
  5. String name = countryName[i];
  6. HSSFRow row = hidden.createRow(i);
  7. HSSFCell cell = row.createCell(0);
  8. cell.setCellValue(name);
  9. }
  10. Name namedCell = workbook.createName();
  11. namedCell.setNameName("hidden");
  12. namedCell.setRefersToFormula("hidden!$A$1:$A$" + countryName.length);
  13. DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden");
  14. CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
  15. HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint);
  16. workbook.setSheetHidden(1, true);
  17. realSheet.addValidationData(validation);
  18. FileOutputStream stream = new FileOutputStream("c:\\range.xls");
  19. workbook.write(stream);
  20. stream.close();

代码示例来源:origin: com.dexcoder/dexcoder-commons

  1. /**
  2. * 创建下拉列表列
  3. *
  4. * @param sheet sheet对象
  5. * @param cell cell对象
  6. * @param firstRowIndex 开始行索引
  7. * @param lastRowIndex 结束行索引
  8. * @param firstCellIndex 开始列索引
  9. * @param lastCellIndex 结束列索引
  10. * @param cellValue 列的值
  11. */
  12. public void createSelectCellStyle(HSSFSheet sheet, HSSFCell cell, int firstRowIndex, int lastRowIndex,
  13. int firstCellIndex, int lastCellIndex, String[] cellValue) {
  14. CellRangeAddressList regions = new CellRangeAddressList(firstRowIndex, lastRowIndex, firstCellIndex,
  15. lastCellIndex);
  16. DVConstraint constraint = DVConstraint.createExplicitListConstraint(cellValue);
  17. HSSFDataValidation dataValidate = new HSSFDataValidation(regions, constraint);
  18. // 加入数据有效性到当前sheet对象
  19. sheet.addValidationData(dataValidate);
  20. // 设置默认显示的值
  21. cell.setCellValue(cellValue[0]);
  22. }

代码示例来源:origin: selfly/dexcoder-assistant

  1. /**
  2. * 创建下拉列表列
  3. *
  4. * @param sheet sheet对象
  5. * @param cell cell对象
  6. * @param firstRowIndex 开始行索引
  7. * @param lastRowIndex 结束行索引
  8. * @param firstCellIndex 开始列索引
  9. * @param lastCellIndex 结束列索引
  10. * @param cellValue 列的值
  11. */
  12. public void createSelectCellStyle(HSSFSheet sheet, HSSFCell cell, int firstRowIndex, int lastRowIndex,
  13. int firstCellIndex, int lastCellIndex, String[] cellValue) {
  14. CellRangeAddressList regions = new CellRangeAddressList(firstRowIndex, lastRowIndex, firstCellIndex,
  15. lastCellIndex);
  16. DVConstraint constraint = DVConstraint.createExplicitListConstraint(cellValue);
  17. HSSFDataValidation dataValidate = new HSSFDataValidation(regions, constraint);
  18. // 加入数据有效性到当前sheet对象
  19. sheet.addValidationData(dataValidate);
  20. // 设置默认显示的值
  21. cell.setCellValue(cellValue[0]);
  22. }

相关文章

HSSFSheet类方法