COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: qvixote on 29 Jul 2014 08:58:24 AM

Title: Custom Excel button and hidding report elements when running in excel
Post by: qvixote on 29 Jul 2014 08:58:24 AM
Hello!

Here I am again with 2 questions related to exporting report to excel.

1. My client asked to hide the "cognos bars" from some reports that need to be public, and I did it using javascript. Now they need to export the report to excel but the button to do it was hidden with the entire upper bar. Is there any way to add a custom button to export the report to excel?

2. In the same report there some elements that I don't want to be displayed when exporting to excel. How can I indicate an element in the report must display only when running as HTML?

Thanks!
Title: Re: Custom Excel button and hidding report elements when running in excel
Post by: torre2011 on 29 Jul 2014 09:10:31 AM
I ran into the same issue and am currently using this solution:

I have a table in the upper right hand corner with an image for the Excel and an HTML item with the following code:
<a href='#' class='listlink' onclick="window[nameSpace].getRV().runExcel()"> Excel Output</a>

This references the following javascript code which is in a HTML item in the header:
<script>
CViewerManager.prototype.runExcel = function ()
{
  var oReq = new ViewerDispatcherEntry(this.getCV());
  oReq.addFormField("ui.action","render");
  oReq.addFormField("run.outputFormat","spreadsheetML");
  this.viewInNewWindowWithResize(oReq);
};

var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if (!fW || fW == undefined) {
  fW = (formWarpRequest_THIS_ ? formWarpRequest_THIS_:formWarpRequest_NS_);
}

  var preFix = "";
  if (fW.elements["cv.id"]) { preFix = fW.elements["cv.id"].value;}
  var nameSpace = "oCV" + preFix;

 

CViewerManager.prototype.viewInNewWindowWithResize = function(oReq, browserHandle)
{
var oldUnload=window.onbeforeunload;
window.onbeforeunload=null;

if (browserHandle != null) {
browserHandle.close();
}
var target = "winNAT_" + ( new Date() ).getTime();
var sPath = this.getCV().getWebContentRoot() + "/" + "rv/blankNewWin.html?cv.id=" + this.getCVId();

var sFormID = "viewForm" + this.getCVId();
var oForm = document.getElementById(sFormID);
if (oForm) {
oForm.parentNode.removeChild(oForm);
}

oForm = document.createElement("form");
oForm.setAttribute("method", "post");
oForm.setAttribute("id", sFormID);
oForm.setAttribute("action", this.getCV().getGateway());
oForm.style.display = "inline";

var oFWR = document["formWarpRequest" + this.getCVId()];
if (oFWR && oFWR["run.outputFormat"]) {
oReq.addFormField("previousFormat", oFWR["run.outputFormat"].value);
}


var formFieldNames = oReq.getFormFields().keys();
for (var index = 0; index < formFieldNames.length; index++)
{
var name = formFieldNames[index];

// we'll force the action and respons format later on so we don't indirectly send this request to the fragment server
// since we're now doing a render, don't pass along the tracking. We still need to pass the
// conversation since we want to reuse the parameters and options
if(name != "cv.responseFormat" && name != "b_action" && name != "m_tracking")
{
oForm.appendChild(createHiddenFormField(name, oReq.getFormField(name)));
}
}

oForm.appendChild(createHiddenFormField("cv.responseFormat", "page"));
oForm.appendChild(createHiddenFormField("b_action", "cognosViewer"));
oForm.appendChild(createHiddenFormField("BIline1", RV_RES.RV_RUNNING));
oForm.appendChild(createHiddenFormField("BIline2", RV_RES.RV_PLEASE_WAIT));


document.body.appendChild(oForm);
oForm.target = target;

browserHandle = window.open(sPath, target, "rv,resizable=1");

window.onbeforeunload=oldUnload;
};


</script>


Then to hide the elements before the report is sent, I simply use Conditional Styles with the following condition:
ReportOutput ()='spreadsheetML'

When this condition is true then I set the report objects "Block" property to "None".

And this has worked great!

Hope it helps  ;D
Title: Re: Custom Excel button and hidding report elements when running in excel
Post by: qvixote on 29 Jul 2014 09:32:44 AM
Thanks for the quick reply! I'll try it and see what happen.
Title: Re: Custom Excel button and hidding report elements when running in excel
Post by: qvixote on 29 Jul 2014 09:43:54 AM
It worked perfectly! Many thanks!