Posts

Showing posts from February, 2017

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(new Perso

Print a progress in Python

Here is how to do this: import sys sys.stdout.write("\r%d" % i) sys.stdout.flush() Writing '\r' will move the cursor back to the beginning of the line. If we want to print a %, we need to print an additional % like the folllowing: sys.stdout.write("\r%d%%" % i)