A common requirement for many reporting applications is to provide the ability to export reports to Microsoft Excel format. This can be challenging for a number of reasons, including:
- Most reporting engines require the use of a report design tool to develop reports.
- Reports designed to be exported to PDF or HTML do not always translate well to XLS format.
- Advanced Excel functionality such as complex forumlas, macros, and charts are not always available through the reporting engines.
jXLS is an open source Java library that greatly simplies this process by providing the ability to use XLS templates as the basis for generating reports in Excel format.
You only need a few lines of code to generate the output … And ( this my favourite ), you do not need to have MS Excel installed on the machine running the code.
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
List staff = new ArrayList();
staff.add(new Employee("Derek", 35, 3000, 0.30));
staff.add(new Employee("Elsa", 28, 1500, 0.15));
staff.add(new Employee("Oleg", 32, 2300, 0.25));
staff.add(new Employee("Neil", 34, 2500, 0.00));
staff.add(new Employee("Maria", 34, 1700, 0.15));
staff.add(new Employee("John", 35, 2800, 0.20));
staff.add(new Employee("Leonid", 29, 1700, 0.20));
Map beans = new HashMap();
beans.put("employee", staff);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS("c:\\in.xls", beans, "c:\\out.xls");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}