Skip to content

Commit

Permalink
upgrade version from 4.5.3 to 4.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
liaochong committed Oct 12, 2024
1 parent f9b8c8d commit 2f90486
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.github.liaochong</groupId>
<artifactId>myexcel</artifactId>
<version>4.5.3</version>
<version>4.5.4</version>
<packaging>jar</packaging>

<name>myexcel</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ protected void createCell(Td td, Sheet sheet, Row currentRow) {

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

private String setDropDownList(Td td, Sheet sheet, String content, CellAddress cellAddress) {
if (content != null && !content.isEmpty()) {
CellRangeAddressList addressList = new CellRangeAddressList(
td.row, td.getRowBound(), td.col, td.getColBound());
CellRangeAddressList addressList;
if (td.dropdownList.isFullColumnReference()) {
addressList = new CellRangeAddressList(
td.row, (isHssf ? XLS_MAX_ROW_COUNT : XLSX_MAX_ROW_COUNT) - td.row, td.col, td.getColBound());
} else {
addressList = new CellRangeAddressList(
td.row, td.getRowBound(), td.col, td.getColBound());
}
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
DropDownLists.Index index = DropDownLists.getHiddenSheetIndex(content, workbook);
String[] list = new String[]{index.firstLine};
DataValidation validation;
boolean linkage = td.dropdownList != null && StringUtil.isNotBlank(td.dropdownList.getParent());
boolean linkage = StringUtil.isNotBlank(td.dropdownList.getParent());
if (linkage) {
CellAddress parentCellAddress = referMapping.get(td.dropdownList.getParent());
String refer = new CellAddress(cellAddress.getRow(), parentCellAddress.getColumn()).formatAsString();
Expand All @@ -633,7 +639,7 @@ private String setDropDownList(Td td, Sheet sheet, String content, CellAddress c
validation.setSuppressDropDownArrow(false);
}
sheet.addValidationData(validation);
return linkage ? null : list[0];
return linkage ? null : td.dropdownList.isShowFirstOption() ? list[0] : null;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class DropdownList {

private String parent;

private boolean fullColumnReference;

private boolean showFirstOption = true;

public String getName() {
return name;
}
Expand All @@ -41,4 +45,20 @@ public String getParent() {
public void setParent(String parent) {
this.parent = parent;
}

public boolean isFullColumnReference() {
return fullColumnReference;
}

public void setFullColumnReference(boolean fullColumnReference) {
this.fullColumnReference = fullColumnReference;
}

public boolean isShowFirstOption() {
return showFirstOption;
}

public void setShowFirstOption(boolean showFirstOption) {
this.showFirstOption = showFirstOption;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,17 @@ private void setTdContent(Element tdElement, Td td) {
}
if (tdElement.hasAttr("dropdownlist") || tdElement.hasAttr("dropDownList")) {
td.tdContentType = ContentTypeEnum.DROP_DOWN_LIST;
td.dropdownList = new DropdownList();
String dropdownListName = tdElement.attr("dropdownlist-name");
if (StringUtil.isNotBlank(dropdownListName)) {
DropdownList dropdownList = new DropdownList();
dropdownList.setName(dropdownListName);
td.dropdownList = dropdownList;
td.dropdownList.setName(dropdownListName);
}
String dropdownListParent = tdElement.attr("dropdownlist-parent");
if (StringUtil.isNotBlank(dropdownListParent)) {
if (td.dropdownList == null) {
td.dropdownList = new DropdownList();
}
td.dropdownList.setParent(dropdownListParent);
}
td.dropdownList.setFullColumnReference(tdElement.hasAttr("dropdownlist-full-column-reference"));
td.dropdownList.setShowFirstOption(!tdElement.hasAttr("dropdownlist-not-show-first-option"));
return;
}
if (Constants.TRUE.equals(content) || Constants.FALSE.equals(content)) {
Expand Down

0 comments on commit 2f90486

Please sign in to comment.