Question

I use pentaho report designer. I have got businessdate parameter in my prpt file. This has the value of the date range which is used to filter the sql query. I am able to handle and modify it while exporting to html however I have a problem in exporting to excel.

The date range comes in the formats below:

 - BETWEEN {d '2014-01-01'} AND {d '2014-01-31'}
 - IN ({d '2014-01-14'},{d '2014-01-15'}, {d '2014-01-19'} ,{d '2014-01-20'},{d '2014-01-21'})

I like to find out max and min date and display it. However in this case with excel, I am happy with displaying them separated with commas like shown below.

- 2014-01-01, 2014-01-31
- 2014-01-14, 2014-01-15, 2014-01-19, 2014-01-20, 2014-01-21

If I use the basic formula show below, it works in in excel but it does not work when I apply it to excel - formula section of the businessDate element in pentaho report designer.

=TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B4,"{d '",""), "BETWEEN", ""), "IN", ""),"'}",", "), " AND ", ""),")",""),"(",))

It does not have to be this way. I am happy with any method suggested to format this raw date range before printing to excel.

Thank you in advance.

Was it helpful?

Solution

After wasting a lot of time, I have found a way which works for all export types. As I said in my question, I was modifying date for html print by using "Structure Tab" --> Select "Master Report" --> "Attributes" Tab --> html -> "append-header" attribute.

 <script type="text/javascript">

    function init() {

    var tableList = document.getElementsByTagName("table");
     var businessDate = document.getElementById("businessDatePeriodSelected");
     businessDate.innerHTML = businessDate.innerHTML+"testDateModified";
    }

    window.onload = init;

    </script>

This piece of code does the job. However just for html. I needed to come up with something new. I was looking for a solution for excel and pdf exports as well.

HERE IS THE SOLUTION: Click on "Data" tab next to the "Structure" tab on the right top side. You will see "Functions" in the tree. Right click and hit "Add functions". Select "Script" -->"Bean-Scripting Framework (BSF)". Select function created under Functions. Give it a name and add the code below to the "Expression" section. [This does not need a starting or ending tag]

/* businessdate is one of my parameters that I like to display on the report.
dataRow is automatically recognized by the interpreter which can be used for calling parameter values. It seems like came out of nowhere.*/


         String value = dataRow.get("businessdate"); 

            value= value.replaceAll("[^0-9\\-\\{\\}]", ""); 
            value= value.replaceAll("[\\{]", ""); // replace all {
            value= value.replaceAll("[\\}]", ","); // replace all }

            value= value.substring(0, value.length()-1);
            String[] dateArr = value.split(",");

            return dateArr[0] +" - "+dateArr[dateArr.length-1]; 

The last thing you need to do is drag and drop your function somewhere suitable on your report. It will locate a textbox which will display the modified businessdate.

If you like to print a parameter on your pentaho report, this does the job for all exports (html, pdf and excel). You can also modify it before printing. This link pretty helpful as the syntax is slightly different at some points.

good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top