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

0. excel 样式

1. 需要工具:hutool

2. maven依赖:

cn.hutool

hutool-all

5.2.5

org.apache.poi

poi-ooxml

3.17

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实现对角线数据复制)