????ASP.NET??????????????
???????????? ???????[ 2012/7/13 10:46:10 ] ????????
?????? ?????????window.print??????????????????????????????????
<script language="Javascript">
function preview()
{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0??prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
<!--?????????-->
<form id="WebForm1" method="post" runat="server">
<center>????????????????</center>
<!--startprint-->
<div align="center">
<asp:DataGrid id="dgShow" runat="server">
<!--?????????-->
</asp:DataGrid>
</div>
<!--endprint-->
<center>?????????2??????</center>
<div align="center">
<input type="button" name="print" value="????????" onclick="preview()">
</div>
<style> @media Print { .Noprn { DISPLAY: none }}
</style>
<p class="Noprn">?????</p>
<table id="datagrid">
<tr>
<td>???</td>
</tr>
</table>
<input class="Noprn" type="button" onclick="window.print()" value="print">
</form>
????WebBrowser ???????
?????? ????????????
??????????????????????WebBrowser??????????????????????????????????????????????????
<object ID=‘WebBrowser1’ WIDTH=0 HEIGHT=0
CLASSID=‘CLSID:8856F961-340A-11D0-A96B-00C04FD705A2’>
//???
WebBrowser1.ExecWB(6??1);
//???????
WebBrowser1.ExecWB(8??1);
//??????
WebBrowser1.ExecWB(7??1);
//?????
WebBrowser1.ExecWB(6??6);
//???????PrintClass
public string DGPrint(DataSet ds)
{
//DGPrint??е?????????DataTable?????????HTML??????????
DataTable myDataTable=new DataTable();
myDataTable=ds.Tables[0];
int myRow=myDataTable.Rows.Count;
int myCol=myDataTable.Columns.Count;
StringBuilder sb=new StringBuilder();
string colHeaders="<html><body>"+"<object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'VIEWASTEXT></object>" +"<table><tr>";
for(int i=0;i<myCol;i++)
{
colHeaders +="<td>"+ myDataTable.Columns[i].ColumnName.ToString()+"</td>";
}
colHeaders += "</tr>";
sb.Append(colHeaders);
for(int i=0;i<myRow;i++)
{
sb.Append("<tr>");
for(int j=0;j<myCol;j++)
{
sb.Append("<td>");
sb.Append(myDataTable.Rows[i][j].ToString().Trim());
sb.Append("</td>");
}
sb.Append("</tr>");
}
sb.Append("</table></body></html>");
colHeaders=sb.ToString();
colHeaders+="<script languge='Javascript'>WebBrowser.ExecWB(6??1); window.opener=null;window.close();</script>";
return(colHeaders);
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11