2014-02-12 13 views
1

我使用pentaho報表設計器。我的prpt文件中有businessdate參數。這具有用於過濾sql查詢的日期範圍的值。我能夠處理和修改它,而出口到HTML但我有出口到Excel中的問題。pentaho在導出爲ex​​cel時修改並打印參數

的日期範圍進來格式如下:

- 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'}) 

我想找出最大和最小日期和顯示。然而,在這種情況下與Excel,我很高興顯示它們用逗號分隔,如下所示。

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

如果我用下面的基本公式顯示,它工作在Excel中,但是當我將它應用於練成這是行不通的 - 在Pentaho報表設計器中的businessDate元素的公式部分。

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

它不一定是這樣。我很高興任何方法建議格式化這個原始日期範圍之前打印到Excel。

預先感謝您。

回答

0

浪費了很多時間之後,我發現了一種適用於所有導出類型的方法。正如我在我的問題中所說的,我使用「結構選項卡」 - >選擇「主報告」 - >「屬性」選項卡 - > html - >「append-header」屬性修改了html打印的日期。

<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> 

這段代碼完成這項工作。但僅適用於html。我需要提出一些新的東西。我正在尋找excel和pdf導出的解決方案。

這裏是解決方案: 點擊右上方「結構」選項卡旁邊的「數據」選項卡。您會在樹中看到「功能」。右鍵單擊並點擊「添加功能」。選擇「Script」 - >「Bean-Scripting Framework(BSF)」。選擇功能下創建的功能。給它一個名字並將下面的代碼添加到「表達式」部分。 [這並不需要一個開始或結束標記]

/* 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]; 

你需要做的最後一件事是拖放你的函數某處適合你的報告。它會找到一個顯示修改後的業務日期的文本框。

如果你喜歡在你的pentaho報表上打印參數,那麼它可以處理所有出口(html,pdf和excel)。打印前您也可以修改它。這個link很有幫助,因爲語法在某些點上稍有不同。

祝你好運。