0

I am working on BIRT crosstab report. In my report i need to create a global array variable and need to populate the array variable based on the column count of crosstab. I am calculating the columnCount in onRender event of the crosstab and and i need to pass this value to a global function and from the result of the global function need to populate the global variable. Then in some of other crosstab or the same crosstab i need to access this array variable.

Simply I am generating column names A,B,C...Z,AA,AB...etc, based on the column count generated in onRender of an data element in crosstab,i need to populate the array varible by passing this count to the global function and then the function returns the excel names for the number it received as param(like 1-A,2-B,3-C,....26-Z,27-AA...etc) this result is added to the array variable.This array variable will be used in another row of a crosstab of data element onRender, i cant do this with dataset bacause there is a sort function applied in crosstab(to overcome default sort of crosstab).

How can i achieve this, or anyother easy way to handle this?

Manikandan Arunachalam
  • 1,470
  • 3
  • 17
  • 32

1 Answers1

0

I got it. A small careless mistake took 4 days..I solved it as follows.

Initialize the global variable and function in Report initialize event.Calling this function from a crosstab data element's onRender event with passing the counter value, the function gets this counter value and finds its equivalent excelcolumn name and insert into global variable.

columnCount = 1;
counter = 1;
names=new Array();
names.push('');     /* for 0th position */    
function toName(number)
{
    name = "";
    while(number>0)
    {
        modulo = (number-1)%26;
        name = String.fromCharCode(65 + modulo).toString()+name;
        number = parseInt((number-modulo)/26);  
    }
    names.push(name);
}

The above code is declared in report initialize event.

Then in a data element pass the counter value to the function as follows. and then increment the counter.

toName(columnCount);
columnCount++;

Then in a data element for which i need excel column name to set excel formula,the onRender method of this element getting the array value for the counter index.

if(counter==columnCount)
{
    counter=1;
}   
this.setDisplayValue(names[counter]);
counter++;

This is how the data element is changed when export to excel by onRender event.

Manikandan Arunachalam
  • 1,470
  • 3
  • 17
  • 32