0

I am using DynamicJasper ver 4.0.2 and I've created the report in Excel format.

The report is having three columns let say A, B and C.
In the footer I want total of column A i.e. SUM(A) and Column B i.e. SUM(B) while total of Column C=(SUM(B)/SUM(A))*100.

However I could able to add total for column A and B by using drb.addGlobalFooterVariable(columnA, DJCalculation.SUM) and drb.addGlobalFooterVariable(columnB, DJCalculation.SUM).

But I'm not able to find the Solution for columnC as per formula explained above.

I googled but I didn't get any relevant post. Please help me.

Alex K
  • 22,315
  • 19
  • 108
  • 236

1 Answers1

1

I got the solution by using CustomExpression class in Dynamic Jasper.Here is an example below,

     private AbstractColumn COLUMN_C;
     DynamicReportBuilder drb = new DynamicReportBuilder();
     COLUMN_C = ColumnBuilder.getNew().setColumnProperty("columnC",Double.class.getName()).setTitle("C").setHeaderStyle(headerStyle).setFixedWidth(false).setStyle(detailCurrencyStyle).setPattern("###0.00;-###0.00").build();
     drb.addGlobalFooterVariable(COLUMN_C, new CustomExpression() {

                @Override
                public Object evaluate(Map fields, Map variables, Map parameters) {
                    double totalOfColumnC = 0.00;
                    totalOfColumnC = ( totalOfColumnB/ totalOfColumnA) * 100;
                    return totalOfColumnC;

                }

                @Override
                public String getClassName() {
                    return Double.class.getName();
                }
            });