mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug
This commit is contained in:
parent
803f1b313c
commit
e645d741c7
@ -46,6 +46,14 @@ public class IndexedComparator<T> implements Comparator<T> {
|
||||
final int index1 = getOrder(o1);
|
||||
final int index2 = getOrder(o2);
|
||||
|
||||
// 任意一个元素不在列表中
|
||||
if(index1 == index2){
|
||||
if(index1 < 0 || index1 == this.array.length){
|
||||
// 任意一个元素不在列表中, 返回原顺序
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return Integer.compare(index1, index2);
|
||||
}
|
||||
|
||||
|
53
hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI66Z6BTest.java
Executable file
53
hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI66Z6BTest.java
Executable file
@ -0,0 +1,53 @@
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class IssueI66Z6BTest {
|
||||
|
||||
/**
|
||||
* 部分字段定义别名后,由于IndexedComparator比较器的问题,会造成字段丢失,已修复
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() {
|
||||
final File destFile = new File("D:/test/0001test.xlsx");
|
||||
FileUtil.del(destFile);
|
||||
|
||||
final List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
|
||||
final Map<String, Object> row1 = new LinkedHashMap<>();
|
||||
row1.put("姓名", "张三");
|
||||
row1.put("年龄", 23);
|
||||
row1.put("成绩", 88.32);
|
||||
row1.put("是否合格", true);
|
||||
row1.put("考试日期", DateUtil.now());
|
||||
dataList.add(row1);
|
||||
|
||||
final Map<String, Object> row2 = new LinkedHashMap<>();
|
||||
row2.put("姓名", "李四");
|
||||
row2.put("年龄", 33);
|
||||
row2.put("成绩", 59.50);
|
||||
row2.put("是否合格", false);
|
||||
row2.put("考试日期", DateUtil.now());
|
||||
dataList.add(row2);
|
||||
|
||||
// 通过工具类创建writer
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(destFile);
|
||||
|
||||
//自定义标题别名
|
||||
writer.addHeaderAlias("姓名", "name");
|
||||
writer.addHeaderAlias("年龄", "age");
|
||||
|
||||
writer.write(dataList, true);
|
||||
writer.close();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user