ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

EasyPoi

2021-06-04 10:05:25  阅读:258  来源: 互联网

标签:name file new date EasyPoi public dou



/**
* @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);
}

标签:name,file,new,date,EasyPoi,public,dou
来源: https://www.cnblogs.com/Bkxk/p/14848280.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有