Posts

Showing posts with the label excel

Generate a Excel file from Spring

We often need to generate a spreadsheet file from server and allow users to download the file. Here is how to do that with Spring using the Apache POI library. Dependency: We need to add the following dependencies in our spring application. Here is the Gradle dependencies. compile group: 'org.apache.poi', name: 'poi', version: '3.15' compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15' Once we add the dependencies we'll be able to access the POI library in our application. Generate WorkBook We need to generate a Workbook object in POI. Here is a sample method that returns a Workbook object public Workbook downloadPersonList() throws IOException {     // sample list. this can be the output of a DB query     List<Person> personList = new ArrayList<>();       personList.add(new Person("nayan", 29));     personList.add(new Person("rafiq", 35)) ;     personList.add(ne...