Export Cognos Report into Excel and PDF using Java script.
Requirement: User wants a Button to Export Report HTML output into Excel & PDF both on a click.
Solution: Using HTML Items and Java scripting this can be achieved.
Put two HTML Items in the
report where you want to create Export Button.
Copy the below mentioned code and paste into HTML items accordingly.
Script for HTML 1:
<SCRIPT>
<!--
function reRunExcel(){
//while Running report
Try
{
oCV_NS_.getRV().viewReport('spreadsheetML');
}
catch(err) {}
//while Testing report
try
{
oCVRS.getRV().viewReport('spreadsheetML');
}
catch(err) {}
}
//-->
</SCRIPT>
<A
href="javascript:reRunExcel();"> </a>
Script for
HTML 2:
<html>
<head>
<script
language="javascript">
function gotourl()
{var
obj=document.all['OutputFormat'];
var value="PDF";
window.onload(gCognosViewer.getRV().viewReport
(value));
function
reRunExcel(){
//while Running
report
try
{
oCV_NS_.getRV().viewReport('spreadsheetML');
}
catch(err) {}
}
}
</script>
</head>
<body>
</body>
<button
onclick="gotourl(); reRunExcel();">Export to Excel/PDF
</Button>




