近日项目中提出需求,需要导出Excel,最开始以为很简单,也没说明需要合并相同内容的行,于是偷个懒,使用原来写好的工具类直接导出。写好后以为okay了,结果,竟然又提供了另一个版本的模板,需要合并内容相同的列,麻烦来了,于是网上各种搜寻,最后找到一个例子,效果是我想要的,感谢大神的贡献,附上链接如下:
https://blog.youkuaiyun.com/qq_33142257/article/details/64929145
于是取下来先看看效果,然后再这基础上自己改进了一下做出了自己想要的效果,如下:
记录一下,以后备用
首先在maven工程的pom.xml文件中添加
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
package com.test.testexcel;
public class PoiModel {
private String content;
private String oldContent;
private int rowIndex;
private int cellIndex;
public String getOldContent() {
return oldContent;
}
public void setOldContent(String oldContent) {
this.oldContent = oldContent;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getRowIndex() {
return rowIndex;
}
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
public int getCellIndex() {
return cellIndex;
}
public void setCellIndex(int cellIndex) {
this.cellIndex = cellIndex;
}
}
package com.test.testexcel;
import java.io.Fi