Get the App
SLTechnology News&Howtos  ›  Development  › 

Java how to export Excel add drop-down box option

Shulou Source: shulou.com Published: 2022-05-31 19:00:00 10月04日 Update

Today, I would like to share with you how Java exports Excel to add drop-down box options related to knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you will learn something after reading this article, let's take a look at it.

Excel for more options in the drop-down box, you need to use a hidden workbook to solve the problem, and use function values to do the options.

Fewer options (generally less than 5):

Private static DataValidation setFewDataValidation (Sheet sheet, String [] textList, int firstRow, int endRow, int firstCol, int endCol) {DataValidationHelper helper = sheet.getDataValidationHelper (); / / load the contents of the drop-down list DataValidationConstraint constraint = helper.createExplicitListConstraint (textList); constraint.setExplicitListValues (textList); / / sets the cell in which the data validity is loaded. The four parameters are: start row, end row, start column, stop column CellRangeAddressList regions = new CellRangeAddressList ((short) firstRow, (short) endRow, (short) firstCol, (short) endCol); / / data validity object return helper.createValidation (constraint, regions);}

There are many options

Create a hidden workbook:

Sheet sheetHidden = wb.createSheet ("Sheet2"); wb.setSheetHidden (1, true)

Each list occupies one column

Of course, you can also use one workbook per list, using only the first column. Here is to use a workbook to use each column, with the first 26 letters, which is generally enough

String [] arr = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" "Z"} For (int j = 0; j < dataList.size (); jacks +) {if (index = = 0) {/ / first drop-down option to directly create rows and columns row = sheetHidden.createRow (j); / create data rows / / sheetHidden.setColumnWidth (j, 4000); / / set column width row.createCell (0) .setCellValue (dataList.get (j)) / / set the value of the corresponding cell} else {/ / not the first drop-down option int rowCount = sheetHidden.getLastRowNum (); if (j

Tags: Drop-down data unit start valid content validity work parameters knowledge articles sources objects jackers generation selection difference very different that is code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB OPPO Reno Linux Apple