Skip to content

Commit 2f90486

Browse files
author
liaochong
committed
upgrade version from 4.5.3 to 4.5.4
1 parent f9b8c8d commit 2f90486

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.github.liaochong</groupId>
1313
<artifactId>myexcel</artifactId>
14-
<version>4.5.3</version>
14+
<version>4.5.4</version>
1515
<packaging>jar</packaging>
1616

1717
<name>myexcel</name>

src/main/java/com/github/liaochong/myexcel/core/AbstractExcelFactory.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ protected void createCell(Td td, Sheet sheet, Row currentRow) {
402402

403403
private String process(Td td, Sheet sheet, Cell cell, String content) {
404404
CellAddress cellAddress = cell.getAddress();
405-
if (td.dropdownList != null) {
405+
if (td.dropdownList.getName() != null) {
406406
referMapping.putIfAbsent(td.dropdownList.getName(), cellAddress);
407407
}
408408
return this.setDropDownList(td, sheet, content, cellAddress);
@@ -608,13 +608,19 @@ private Cell setLink(Td td, Row currentRow, HyperlinkType hyperlinkType) {
608608

609609
private String setDropDownList(Td td, Sheet sheet, String content, CellAddress cellAddress) {
610610
if (content != null && !content.isEmpty()) {
611-
CellRangeAddressList addressList = new CellRangeAddressList(
612-
td.row, td.getRowBound(), td.col, td.getColBound());
611+
CellRangeAddressList addressList;
612+
if (td.dropdownList.isFullColumnReference()) {
613+
addressList = new CellRangeAddressList(
614+
td.row, (isHssf ? XLS_MAX_ROW_COUNT : XLSX_MAX_ROW_COUNT) - td.row, td.col, td.getColBound());
615+
} else {
616+
addressList = new CellRangeAddressList(
617+
td.row, td.getRowBound(), td.col, td.getColBound());
618+
}
613619
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
614620
DropDownLists.Index index = DropDownLists.getHiddenSheetIndex(content, workbook);
615621
String[] list = new String[]{index.firstLine};
616622
DataValidation validation;
617-
boolean linkage = td.dropdownList != null && StringUtil.isNotBlank(td.dropdownList.getParent());
623+
boolean linkage = StringUtil.isNotBlank(td.dropdownList.getParent());
618624
if (linkage) {
619625
CellAddress parentCellAddress = referMapping.get(td.dropdownList.getParent());
620626
String refer = new CellAddress(cellAddress.getRow(), parentCellAddress.getColumn()).formatAsString();
@@ -633,7 +639,7 @@ private String setDropDownList(Td td, Sheet sheet, String content, CellAddress c
633639
validation.setSuppressDropDownArrow(false);
634640
}
635641
sheet.addValidationData(validation);
636-
return linkage ? null : list[0];
642+
return linkage ? null : td.dropdownList.isShowFirstOption() ? list[0] : null;
637643
}
638644
return null;
639645
}

src/main/java/com/github/liaochong/myexcel/core/parser/DropdownList.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class DropdownList {
2626

2727
private String parent;
2828

29+
private boolean fullColumnReference;
30+
31+
private boolean showFirstOption = true;
32+
2933
public String getName() {
3034
return name;
3135
}
@@ -41,4 +45,20 @@ public String getParent() {
4145
public void setParent(String parent) {
4246
this.parent = parent;
4347
}
48+
49+
public boolean isFullColumnReference() {
50+
return fullColumnReference;
51+
}
52+
53+
public void setFullColumnReference(boolean fullColumnReference) {
54+
this.fullColumnReference = fullColumnReference;
55+
}
56+
57+
public boolean isShowFirstOption() {
58+
return showFirstOption;
59+
}
60+
61+
public void setShowFirstOption(boolean showFirstOption) {
62+
this.showFirstOption = showFirstOption;
63+
}
4464
}

src/main/java/com/github/liaochong/myexcel/core/parser/HtmlTableParser.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,17 @@ private void setTdContent(Element tdElement, Td td) {
408408
}
409409
if (tdElement.hasAttr("dropdownlist") || tdElement.hasAttr("dropDownList")) {
410410
td.tdContentType = ContentTypeEnum.DROP_DOWN_LIST;
411+
td.dropdownList = new DropdownList();
411412
String dropdownListName = tdElement.attr("dropdownlist-name");
412413
if (StringUtil.isNotBlank(dropdownListName)) {
413-
DropdownList dropdownList = new DropdownList();
414-
dropdownList.setName(dropdownListName);
415-
td.dropdownList = dropdownList;
414+
td.dropdownList.setName(dropdownListName);
416415
}
417416
String dropdownListParent = tdElement.attr("dropdownlist-parent");
418417
if (StringUtil.isNotBlank(dropdownListParent)) {
419-
if (td.dropdownList == null) {
420-
td.dropdownList = new DropdownList();
421-
}
422418
td.dropdownList.setParent(dropdownListParent);
423419
}
420+
td.dropdownList.setFullColumnReference(tdElement.hasAttr("dropdownlist-full-column-reference"));
421+
td.dropdownList.setShowFirstOption(!tdElement.hasAttr("dropdownlist-not-show-first-option"));
424422
return;
425423
}
426424
if (Constants.TRUE.equals(content) || Constants.FALSE.equals(content)) {

0 commit comments

Comments
 (0)