Skip to content

Commit 83c8581

Browse files
authored
Merge pull request #434 from liaochong/feature/4.5.4
Feature/4.5.4
2 parents f9b8c8d + eb745ba commit 83c8581

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
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>
@@ -22,7 +22,7 @@
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<java.version>1.8</java.version>
25-
<poi.version>5.2.5</poi.version>
25+
<poi.version>5.3.0</poi.version>
2626
<jsoup.version>1.16.2</jsoup.version>
2727
<lombok.version>1.18.22</lombok.version>
2828
<beetl.version>3.15.4.RELEASE</beetl.version>

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/context/ReadContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public void reset(T object, FieldDefinition fieldDefinition, String val, int row
6060
this.val = val;
6161
this.rowNum = rowNum;
6262
this.colNum = colNum;
63+
// for DefaultExcelReader
64+
if (readConfig == null) {
65+
this.readConfig = new SaxExcelReader.ReadConfig<>(-1);
66+
}
6367
}
6468

6569
public void revert() {

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)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Tr {
3636
/**
3737
* 最大宽度
3838
*/
39-
public Map<Integer, Integer> colWidthMap;
39+
public Map<Integer, Integer> colWidthMap = Collections.emptyMap();
4040
/**
4141
* 是否可见
4242
*/

0 commit comments

Comments
 (0)