|
16 | 16 | package com.github.liaochong.myexcel.core; |
17 | 17 |
|
18 | 18 | import com.github.liaochong.myexcel.core.parser.ContentTypeEnum; |
| 19 | +import com.github.liaochong.myexcel.core.parser.DropDownLists; |
19 | 20 | import com.github.liaochong.myexcel.core.parser.HtmlTableParser; |
20 | 21 | import com.github.liaochong.myexcel.core.parser.Td; |
21 | 22 | import com.github.liaochong.myexcel.core.parser.Tr; |
@@ -564,29 +565,38 @@ private Cell setLink(Td td, Row currentRow, HyperlinkType hyperlinkType) { |
564 | 565 | } |
565 | 566 |
|
566 | 567 | private String setDropDownList(Td td, Sheet sheet, String content) { |
567 | | - if (content.length() > 250) { |
568 | | - throw new IllegalArgumentException("The total number of words in the drop-down list should not exceed 250."); |
569 | | - } |
570 | | - CellRangeAddressList addressList = new CellRangeAddressList( |
| 568 | + if (content != null && !content.isEmpty()) { |
| 569 | + CellRangeAddressList addressList = new CellRangeAddressList( |
571 | 570 | td.row, td.getRowBound(), td.col, td.getColBound()); |
572 | | - DataValidationHelper dvHelper = sheet.getDataValidationHelper(); |
573 | | - String[] list = content.split(","); |
574 | | - DataValidationConstraint dvConstraint = dvHelper.createExplicitListConstraint(list); |
575 | | - DataValidation validation = dvHelper.createValidation( |
576 | | - dvConstraint, addressList); |
577 | | - if (td.promptContainer != null) { |
578 | | - validation.createPromptBox(td.promptContainer.title, td.promptContainer.text); |
579 | | - validation.setShowPromptBox(true); |
580 | | - } |
581 | | - if (validation instanceof XSSFDataValidation) { |
582 | | - validation.setSuppressDropDownArrow(true); |
583 | | - validation.setShowErrorBox(true); |
584 | | - } else { |
585 | | - validation.setSuppressDropDownArrow(false); |
586 | | - } |
587 | | - sheet.addValidationData(validation); |
588 | | - if (list.length > 0) { |
589 | | - return list[0]; |
| 571 | + DataValidationHelper dvHelper = sheet.getDataValidationHelper(); |
| 572 | + String[] list; |
| 573 | + DataValidation validation; |
| 574 | + if (content.length() <= 250) { |
| 575 | + list = content.split(","); |
| 576 | + DataValidationConstraint dvConstraint = dvHelper.createExplicitListConstraint(list); |
| 577 | + validation = dvHelper.createValidation( |
| 578 | + dvConstraint, addressList); |
| 579 | + |
| 580 | + } else { |
| 581 | + DropDownLists.Index index = DropDownLists.getHiddenSheetIndex(content, workbook); |
| 582 | + list = new String[]{index.firstLine}; |
| 583 | + validation = dvHelper.createValidation(dvHelper.createFormulaListConstraint(index.path), addressList); |
| 584 | + } |
| 585 | + |
| 586 | + if (td.promptContainer != null) { |
| 587 | + validation.createPromptBox(td.promptContainer.title, td.promptContainer.text); |
| 588 | + validation.setShowPromptBox(true); |
| 589 | + } |
| 590 | + if (validation instanceof XSSFDataValidation) { |
| 591 | + validation.setSuppressDropDownArrow(true); |
| 592 | + validation.setShowErrorBox(true); |
| 593 | + } else { |
| 594 | + validation.setSuppressDropDownArrow(false); |
| 595 | + } |
| 596 | + sheet.addValidationData(validation); |
| 597 | + if (list.length > 0) { |
| 598 | + return list[0]; |
| 599 | + } |
590 | 600 | } |
591 | 601 | return null; |
592 | 602 | } |
|
0 commit comments