What are the best methods for rendering Excel reports in Java?

I need to create an Excel report that looks like this: Excel report

I know that this can be done with libraries like JExcelApi and Apache POI . However, I would like to know if there are ways to achieve this by writing a template similar to creating Apache Velocity templates for sending emails.

If there is a standard approach with good practice for creating such reports, what is it?

+6
source share
2 answers

Why not create a template using Excel? Use placeholders (for example, $ {name.of.field}) for the values ​​you want to replace, but otherwise put everything as needed. Use another placeholder to mark the end of the template (this will allow you to write comments or other data outside this space to document your template).

Then, either through JExcelApi or Apache POI,

  • open the template file and find the end marker of the template.
  • open target file
  • for each record, copy the fields from the template by substituting the $ {xyz} values ​​for their actual contents and stop when you reach the end marker of the template.
  • close target and pattern

Changing the template will be extremely simple. The only problem is synchronizing the field names.

+7
source

You can use a standard Java report library such as i-net Clear Reports and use the excel output format.

+1
source

Source: https://habr.com/ru/post/922036/


All Articles