关于限制水晶报表的导出格式

最近有业务需求,在使用水晶报表时导出格式要求限制为PDF,但是水晶报表的reportviewer没有提供这样的选项,没有办法只好使用hack的水晶报表的到处对话框的方式来实现。

具体实现为找到 “\aspnet_client\system_web\2_0_50727\CrystalReportWebFormViewer4\html\crystalexportdialog.htm” 文件,修改为以下代码:

 

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
	</head>
	<body>
		<script language="javascript">
<!--
// export UI functions
function check(obj) {
	return !obj.disabled;
}

function toggleRangeFields(obj) {
	if( obj.id == "radio1") {
		document.Export.from.disabled = true;
		document.Export.to.disabled = true;
	}
	else {
		document.Export.from.disabled = false;
		document.Export.to.disabled = false;
	}
	return check(obj);
}

function checkDisableRange() {
	if( document.Export.exportformat.value == "CrystalReports"
		|| document.Export.exportformat.value == "RecordToMSExcel" ) {
		if( document.Export.isRange[1].checked ) {
			document.Export.isRange[0].checked = true;
		}
		document.Export.isRange[1].disabled = true;
		document.Export.from.disabled = true;
		document.Export.to.disabled = true;
	}
	else {
		document.Export.isRange[1].disabled = false;
	}
}

function isValidNumber(number) {
	var nonDigit = /\D+/;
	if( nonDigit.test(number) || number == '0' || number == "") {
		return false;
	}
	return true;
}

function checkValuesAndSubmit() {
	if( document.Export.isRange[1].checked ) {
		if (!isValidNumber(document.Export.from.value) || !isValidNumber(document.Export.to.value) || (parseInt(document.Export.from.value, 10) > 

parseInt(document.Export.to.value, 10))) {
			alert(parent.parent.opener.L_InvalidPageRange);
			return;
		}
	}
	if( document.Export.exportformat != null && document.Export.exportformat.selectedIndex == 0 ) {
		alert(parent.parent.opener.L_ExportFormat);
		return;
	}
	document.Export.action = opener.document.getElementById('crystal_handler_page').value;
	document.Export.submit();
}

function init() {
    document.getElementById ('radio1').focus ();
    if (document.getElementById('reportsource')) {
	    document.getElementById('reportsource').value = parent.opener.document.getElementById('crystal_print_rptsrc').value;
	}
	if (document.getElementById('viewstate')) {
	    document.getElementById('viewstate').value = parent.opener.document.getElementById('crystal_print_vs').value;
	}
}

document.write(parent.parent.opener.getExportDialog());

var formatselect=document.getElementById('exportFormatList');
formatselect.options.length = 0; 
formatselect.options[0]=new Option("格式","");
formatselect.options[1]=new Option("Acrobat 格式 (PDF)","PDF");
-->
		</script>
	</body>
</html>

 

 

 

重点就是
var formatselect=document.getElementById('exportFormatList');
formatselect.options.length = 0; 
formatselect.options[0]=new Option("格式","");
formatselect.options[1]=new Option("Acrobat 格式 (PDF)","PDF");


用这个替换掉了原来的格式选择框
posted @ 2010-04-08 19:48  Flymouse  阅读(493)  评论(0编辑  收藏  举报