打印可以用控件实现,保存为excel也可以用POI实现,不过如果仅仅是对当前页面的指定区域作打印或者Excel导出可以用js实现,还是挺简单的.
保存为Excel:
function saveAsExcel(HeadName, DivName) {
var s = "<center>" + HeadName + "</center>" + "\r\n";
s += DivName.innerHTML;
var xlsWindow = window.open("", "_blank", "width=1,height=1,scrollbars=no,toolbar=no");
xlsWindow.document.write(s);
xlsWindow.document.close();
xlsWindow.document.execCommand('Saveas', true, '%homeDrive%\\Data.xls')
xlsWindow.close();
}
打印当前页面:
function PrintDataSoure(HeadName1,HeadName2,HeadName3,DivName,TailName1) {
var oldBody=document.body.innerHTML;
var Div1=DivName.innerHTML;
var css = '<style type="text/css" media=all>' +
'p { line-height: 120%}' +
'.fhead { font-size: 9pt; text-decoration: none; color: 104A7B}' +
'.ftitle { line-height: 120%; font-size: 18px; color: #000000}' +
'td { font-size: 10px; color: #000000}' +
'</style>' ;
var body ='<table width="640" border="0" cellspacing="0" cellpadding="5">' +
' <tr> ' +
' <td class="fbody">' +
' <b><div align="center">'+'<font size="+1" class=fhead>'+ HeadName1 + '</div>'+'</font></b>'+
' <b><div align="center">'+'<font size="+1" class=fhead>'+ HeadName2 + ' ' + HeadName3 +'</div></font></b>'+
' </td>' +
' </tr>' +
' <tr> ' +
' <td class="fbody">' +
' <div align="center" class=ftitle>' + Div1 + '</div>'+
' <b><div align="right">'+'<font size="+1" class=fhead>'+ ' </div>'+'</font></b>'+
' <b><div align="right">'+'<font size="+1" class=fhead>'+ TailName1 + '</div>'+'</font></b>'+
' </td>' +
' </tr>' +
'</table>';
document.body.innerHTML = '<center>' + css + body +'<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>'+'</center>';
wb.execwb(6,6);
document.body.innerHTML=oldBody;
}