数据导出,导入

Posted 小小小龙龙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据导出,导入相关的知识,希望对你有一定的参考价值。

利用easypoi把数据导出:

1、引入easypoi包

<!-- https://mvnrepository.com/artifact/org.jeecg/easypoi-base -->
<dependency>
    <groupId>org.jeecg</groupId>
    <artifactId>easypoi-base</artifactId>
    <version>2.4.0</version>
</dependency>

 

2、导出数据实体类

 

@ExcelTarget("Data")
public class Data {

    @Excel(name=" ")
    private Integer id;

    

    @Excel(name="标题")
    private String title;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

3、

@GetMapping("/data")
    public void data(HttpServletResponse response, String ids, OutputStream os) throws Exception {
List lists = new ArrayList();
        if (!Assert.isEmpty(idsStr)) {
            String[] ids = idsStr.split(",");
            List list = ***.exportByIds(ids);
            for(int i = 0;i<list.size();i++) {
                Data data = new Data();
                data.setId(i+1);
                data.setTitle(list.get(i).getTitle());
                lists.add(data);
            }
        }
        //定义导出参数
        ExportParams params = new ExportParams();
        params.setTitle("设置表头");
        Workbook workbook =  ExcelExportUtil.exportExcel(params, CollectFile_export.class, lists);
        String fname = "文件名"+ DateUtil.dateToString("yyyy-MM-dd", new Date());
        fname = URLEncoder.encode(fname,"UTF-8");
        response.reset();//清空输出流
        response.setCharacterEncoding("UTF-8");//设置相应内容的编码格式
        response.setHeader("Content-Disposition","attachment;filename="+new String(fname.getBytes("UTF-8"),"GBK")+".xls");
        response.setContentType("application/msexcel");//定义输出类型
        //将文件写入输出流
        workbook.write(os);
        workbook.close();
        os.close();
    }

  

 

数据导入

@RequestMapping("admin/data")
	@ResponseBody
	public ReturnBean enterprise_export_insert(HttpServletRequest request, @RequestParam("excelFile") MultipartFile file) {
		ReturnBean rb;
		// 导入参数设置
		ImportParams params = new ImportParams();
		params.setTitleRows(0);
		params.setHeadRows(1);
		params.setNeedSave(false);
		try {
			List<Enterprise_export> dataList = ExcelImportUtil.importExcel(file.getInputStream(), Enterprise_export.class, params);
			System.out.println(dataList);
			enterpriseService.insertExport(dataList);
			rb = ReturnBean.getSuccessReturnBean();
		} catch (Exception e) {
			rb = ReturnBean.getErrorReturnBean();
		}
		return rb;
	}

  

以上是关于数据导出,导入的主要内容,如果未能解决你的问题,请参考以下文章

C#导入导出数据到Excel的通用类代码

UNITY记录——导入透明视频

MySQL导入导出数据时遇到Tab符号和换行符号怎么办

java把数据导出为excel,如何实现每十条数据导入一个excel中,每十条数据导入一个excel中

Spring Boot - 集成 EasyExcel 实现数据导入导出功能

导出 iPad 应用数据的存档格式建议?压缩包?