Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java how to export Excel add drop-down box option

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report