Skip to content

Commit

Permalink
Merge pull request #434 from liaochong/feature/4.5.4
Browse files Browse the repository at this point in the history
Feature/4.5.4
  • Loading branch information
liaochong authored Nov 14, 2024
2 parents f9b8c8d + eb745ba commit 83c8581
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
4 changes: 2 additions & 2 deletions 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 All @@ -22,7 +22,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<poi.version>5.2.5</poi.version>
<poi.version>5.3.0</poi.version>
<jsoup.version>1.16.2</jsoup.version>
<lombok.version>1.18.22</lombok.version>
<beetl.version>3.15.4.RELEASE</beetl.version>
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 @@ -60,6 +60,10 @@ public void reset(T object, FieldDefinition fieldDefinition, String val, int row
this.val = val;
this.rowNum = rowNum;
this.colNum = colNum;
// for DefaultExcelReader
if (readConfig == null) {
this.readConfig = new SaxExcelReader.ReadConfig<>(-1);
}
}

public void revert() {
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Tr {
/**
* 最大宽度
*/
public Map<Integer, Integer> colWidthMap;
public Map<Integer, Integer> colWidthMap = Collections.emptyMap();
/**
* 是否可见
*/
Expand Down

0 comments on commit 83c8581

Please sign in to comment.