Removing empty crosstab columns with JavaScript works in Cognos Viewer but not in Excel export - Stack Overflow

I have a Crosstab in IBM Cognos with a Variable that sometimes results in empty columns. I used JavaScr

I have a Crosstab in IBM Cognos with a Variable that sometimes results in empty columns. I used JavaScript to remove these empty columns dynamically, and it works perfectly in Cognos Viewer.

However, when I export the report to Excel, the empty columns still appear.

Here is a simplified version of the JavaScript code I am using:

    document.querySelectorAll('tr').forEach(row => {
        row.querySelectorAll('td').forEach(td => {
       if (!td.textContent.trim()) {
          td.remove(); 
        }
     });
    });

I have a Crosstab in IBM Cognos with a Variable that sometimes results in empty columns. I used JavaScript to remove these empty columns dynamically, and it works perfectly in Cognos Viewer.

However, when I export the report to Excel, the empty columns still appear.

Here is a simplified version of the JavaScript code I am using:

    document.querySelectorAll('tr').forEach(row => {
        row.querySelectorAll('td').forEach(td => {
       if (!td.textContent.trim()) {
          td.remove(); 
        }
     });
    });

Share Improve this question edited Mar 6 at 8:15 Steven 2,1213 gold badges23 silver badges35 bronze badges asked Mar 6 at 8:04 Hosna BigdeliHosna Bigdeli 11 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 1

Empty columns and rows can be removed via the suppress option on the crosstab container. If the entire row and or column is empty, missing or zero the supress will remove them from all outputs without the need of JS.

https://www.ibm/docs/en/cognos-analytics/11.1.0?topic=cells-use-cognos-analytics-suppression

Your JavaScript is performing actions on the HTML after the data has arrived. The data already exists at that point. So the JavaScript is simply hiding elements from the web page. Running the report to the Excel output format, Cognos will include the data behind the HTML that it generated for the crosstab visualization.

Just in case "Excel" is not the specific output format you are asking about...
If you are outputting to Excel Data or CSV formats, Cognos Analytics returns the results of the query, not the results of the visualization. So your results could be confusing because of that.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744990736a4604889.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信