EasyPoi
2021/6/4 10:20:54
本文主要是介绍EasyPoi,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
/** * @author Administrator */ public class DemoData { @Excel(name = "字符串标题",mergeVertical = true,needMerge=true) private String name; @Excel(name = "日期标题", format = "yyyy-MM-dd HH:mm:ss") private Date date; @Excel(name = "数字标题",suffix="%") private Double dou; @Excel(name = "图片",type = 2,width = 30 , height = 50) private String file; public DemoData() { } public DemoData(String name, Date date, Double dou, String file) { this.name = name; this.date = date; this.dou = dou; this.file = file; } @Override public String toString() { return "DemoData{" + "name='" + name + '\'' + ", date='" + date + '\'' + ", dou='" + dou + '\'' + ", file=" + file + '}'; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public Double getDou() { return dou; } public void setDou(Double dou) { this.dou = dou; } public String getFile() { return file; } public void setFile(String file) { this.file = file; } } ======================
public class writer { public void main(String[] args) throws Exception { /** * 读 */ read(); /** * 写 */ // writer(); } public void read() throws Exception { FileInputStream fileInputStream = new FileInputStream("E:/test/test20210603194325.xlsx"); //默认选择第一个sheet ImportParams params = new ImportParams(); params.setStartSheetIndex(0); List<DemoData> importList = ExcelImportUtil.importExcel(fileInputStream,DemoData.class,params); for (DemoData data : importList){ System.out.println(DateUtil.format(data.getDate(),"yyyy-MM-dd")); System.out.println(JSON.toJSONString(data)); } } public void writer() throws IOException { List<DemoData> list = new ArrayList<>(); DemoData data = new DemoData("文件",new Date(),3.14,"E:\\test\\1622531517(1).jpg"); list.add(data); //模板写出 // TemplateExportParams templateExport = new TemplateExportParams( // "E:\\test\\moban.xlsx", true); // Map<String,Object> map = new HashMap<>(); // List<Map<String, Object>> list1 = new ArrayList<>(); // 创建数据对象 // Map<String, Object> temp1 = new HashMap<String, Object>(); // // 创建图片 // ImageEntity image1 = new ImageEntity(); // image1.setHeight(2000); // image1.setWidth(5000); // image1.setUrl("E:\\test\\1622531517(1).jpg"); // // // temp1.put("name","树"); // temp1.put("date",new Date()) ; // temp1.put("dou",3.14) ; // temp1.put("file", image1); // // // list1.add(temp1); // // map.put("i",list1); ExportParams exportParams = new ExportParams(); exportParams.setSheetName("sheet1"); Workbook workbook = ExcelExportUtil.exportExcel(exportParams,DemoData.class,list); // Workbook workbook = ExcelExportUtil.exportExcel(templateExport,map); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); FileOutputStream outputStream = new FileOutputStream("E:/test/test"+sdf.format(new Date())+".xlsx"); workbook.write(outputStream); }
这篇关于EasyPoi的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南