美文网首页
2. excel java实现对角线数据复制

2. excel java实现对角线数据复制

作者: 逗不一样 | 来源:发表于2021-03-28 17:00 被阅读0次

0. excel 样式

1. 需要工具:hutool

2. maven依赖:

<dependency>

<groupId>cn.hutool</groupId>

<artifactId>hutool-all</artifactId>

<version>5.2.5</version>

</dependency>

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi-ooxml</artifactId>

<version>3.17</version>

</dependency>

3. java代码:

public static void main(String[] args) {

ExcelReader reader = ExcelUtil.getReader("E:/test.xlsx");

List> readAll = reader.readAll();

Integer m =2;

Map indexHeader =new HashMap<>();

indexHeader.put(0,"100");

indexHeader.put(1,"201");

indexHeader.put(2,"202");

indexHeader.put(3,"203");

indexHeader.put(4,"204");

for (int i =0; i < readAll.size(); i++) {

LinkedHashMap linkedHashMap = (LinkedHashMap) readAll.get(i);

for (int j = m; j < linkedHashMap.size(); j++) {

LinkedHashMap clomn = (LinkedHashMap) readAll.get(j -1);

String clomnHeader = indexHeader.get(i);

String header = indexHeader.get(j -1);

linkedHashMap.put(header, clomn.get(clomnHeader));

}

m = m +1;

}

//通过工具类创建writer

    ExcelWriter writer = ExcelUtil.getWriter("E:/testNew.xlsx");

//一次性写出内容,强制输出标题

    writer.write(readAll,true);

//关闭writer,释放内存

    writer.close();

}

相关文章

网友评论

      本文标题:2. excel java实现对角线数据复制

      本文链接:https://www.haomeiwen.com/subject/kynphltx.html