Giter Club home page Giter Club logo

excel-spring-boot-starter's Introduction

EasyExcel

EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目。在尽可能节约内存的情况下支持读写百M的Excel。 64M内存1分钟内读取75M(46W行25列)的Excel,当然还有急速模式能更快,但是内存占用会在100M多一点

spring boot stater依赖

  • 方便在 web 环境下使用 easyexcel ,已上传至 maven 仓库
<dependency>
    <groupId>com.pig4cloud.excel</groupId>
    <artifactId>excel-spring-boot-starter</artifactId>
    <version>0.0.5</version>
</dependency>

使用方法

只需要在 Controller 层返回 List 并增加 @ResponseExcel注解即可

@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ResponseExcel {
	String name() default "";
	ExcelTypeEnum suffix() default ExcelTypeEnum.XLSX;
	String password() default "";
	String[] sheet() default {};
	boolean inMemory() default false;
	String template() default "";
	String[] include() default {};
	String[] exclude() default {};
	Class<? extends WriteHandler>[] writeHandler() default {};
	Class<? extends Converter>[] converter() default {};
}

基础用法

  • 返回单 sheet, 全部字段导出
@ResponseExcel(name = "lengleng", sheet = "demoList")
@GetMapping("/e1")
public List<DemoData> e1() {
    List<DemoData> dataList = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        DemoData data = new DemoData();
        data.setUsername("tr1" + i);
        data.setPassword("tr2" + i);
        dataList.add(data);
    }
    return dataList;
}
// 实体对象

@Data
public class DemoData {
	private String username;
	private String password;
}

  • 自定义字段属性
@Data
public class DemoData {
    @ColumnWidth(50)  // 定义宽度
	@ExcelProperty("用户名") // 定义列名称
    @ContentStyle(fillPatternType = FillPatternType.SOLID_FOREGROUND, fillForegroundColor = 40)
	private String username;
	@ExcelProperty("密码")
	private String password;
}

  • 忽略部分字段
@Data
public class DemoData {
    @ColumnWidth(50)  // 定义宽度
	@ExcelProperty("用户名") // 定义列名称
    @ContentStyle(fillPatternType = FillPatternType.SOLID_FOREGROUND, fillForegroundColor = 40)
	private String username;
	@ExcelProperty("密码")
	private String password;
}

导出多sheet

@ResponseExcel(name = "lengleng", sheet = {"第一个sheet","第二个sheet"})
@GetMapping("/e1")
public List<List<DemoData>> e1() {
    List<List<DemoData>> lists = new ArrayList<>();
    lists.add(list());
    lists.add(list());
    return lists;
}

设置导出加密码

	@ResponseExcel(name = "lengleng", sheet = "sheetName",password = "lengleng")
	@GetMapping("/e1")
	public List<List<DemoData>> e1() {
		List<List<DemoData>> lists = new ArrayList<>();
		lists.add(list());
		lists.add(list());
		return lists;
	}

高级用法模板导出

@ResponseExcel(name = "模板测试excel", sheet = "sheetName",template = "example.xlsx")
@GetMapping("/e1")
public List<DemoData> e1() {
    return list();
}

其他用法

excel-spring-boot-starter's People

Contributors

lltx avatar chunmenglu avatar hccake avatar lishangbu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.