https://download.csdn.net/download/qq_39706570/12524634
1、本项目只集成了导入导出Excel功能,不需要配置相关文件;
2、工具类高内聚封装,没有其他多余组件的集成;
3、适用导出List
/**
* @author SargerasWang
*/
package com.sargeraswang.util.ExcelUtil;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
/**
* 以List
package com.sargeraswang.util.ExcelUtil;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
public class TestExportBean {
@Test
public void exportXls() throws IOException {
//用排序的Map且Map的键应与ExcelCell注解的index对应
Map map = new LinkedHashMap<>();
//这里注意与实体类的@ExcelCell中的index顺序对应。
map.put("name","姓名");
map.put("age","年龄");
map.put("className","班级");
map.put("createTime","出生日期");
Collection
/**
* @author SargerasWang
*/
package com.sargeraswang.util.ExcelUtil;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Map;
/**
* 测试导入Excel 97/2003
*/
public class TestImportExcel {
@Test
public void importXls() throws FileNotFoundException {
File f=new File("C:\\Users\\Administrator\\Desktop\\a.xlsx");
InputStream inputStream= new FileInputStream(f);
ExcelLogs logs =new ExcelLogs();
Collection importExcel ;
try {
importExcel = ExcelUtil.importExcel(Map.class, inputStream, "yyyy/MM/dd HH:mm:ss", logs , 0);
} finally {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
for(Map m : importExcel){
System.out.println(m);
}
}
}