Giter VIP home page Giter VIP logo

excel-exporter-java's Introduction

Generic Excel Exporter

This project shows implementation a generic excel exporter developed in Java using Spring REST.


ExcelExporterService

This service works with the HttpServletResponse, filename and the items.

@GetMapping("/export/products")
public void exportProductsToExcel(HttpServletResponse response) throws IOException, IllegalAccessException {

  var products = dataService.findAllProduct();

  ExcelExporterService excelExporterService = new ExcelExporterService();

  excelExporterService.export(response, "Produtos", products);
}

View code

@ExportableField annotation

This annotation is used for filter all class attributes that will be export.

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExportableField {

  public String name() default "";
  
}

View code

Product Class

All attributes with @ExportableField annotation will be exportable, and value passed on name attribute will appear on Excel file, if doesn't setting, the default value shown will be the variable name.

public class Product {

  @ExportableField(name = "Código")
  private Long code;
  
  @ExportableField(name = "Nome do produto")
  private String description;
  
  @ExportableField(name = "Preço")
  private Double price = 0.0;
  
  @ExportableField(name = "Categoria")
  private Category category;
  
  @ExportableField()
  private Stock stock;
  
}

View code

Product Excel File

Dependencies

  • Java 11
  • Apache POI 5.0.0

💪 Contributions are welcome!

Developed by Marcio Costa

excel-exporter-java's People

Contributors

mcosta21 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

leandrotech

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.