zoukankan
html css js c++ java
Web页面打印及GridView导出到Excel
打印Web页面
在头部<head>加入
打印事件
<
script language
=
javascript
>
function
doPrint()
{
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>
在<body>间加入
打印按钮和打印设置
<
OBJECT
id
="WebBrowser"
classid
="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
height
="0"
width
="0"
VIEWASTEXT
>
</
OBJECT
>
<
div
align
="center"
>
<
a
href
="javascript:; "
onClick
= "doPrint() "
><
img
src
="images/d-y.jpg"
border
="0"
/></
a
>
<
input
class
="NOPRINT"
onclick
="document.all.WebBrowser.ExecWB(8,1)"
type
="button"
title
="打印设置"
>
</
div
>
打印的内容
打印的内容
<!--
startprint
-->
<
form
id
="form1"
runat
="server"
>
<
table
class
="tabp"
width
="650"
height
="700"
align
="center"
>
<
tr
>
<
td
align
="center"
valign
="top"
bgcolor
="#FFFFFF"
>
<!--
打印的内容
-->
</
td
>
</
tr
>
</
table
>
</
form
>
<!--
endprint
-->
按下打印按钮后,JS代码截取<!--startprint-->和<!--endprint--> 之间的内容打印
页面设置按钮是为了去除页脚页面,默认是会打印页面的路径,即http://www.???.aspx?Id=?和页面的Title。
那俩个标记一定要放在form外面,要不会多一行内容出来。
gridview导出到excel
导出事件
protected
void
btnLoad_Click(
object
sender, EventArgs e)
{
Response.Buffer
=
true
;
Response.Charset
=
"
gb2312
"
;
Response.ContentEncoding
=
System.Text.Encoding.GetEncoding(
"
GB2312
"
);
Response.AppendHeader(
"
content-disposition
"
,
"
attachment;filename=\
""
+ System.Web.HttpUtility.UrlEncode(DateTime.Now.ToString(
"
yyyy
-
MM
-
dd
"
), System.Text.Encoding.UTF8) +
"
.xls\
""
);
Response.ContentType
=
"
application/ms-excel
"
;
this
.EnableViewState
=
false
;
StringWriter tw
=
new
StringWriter();
HtmlTextWriter hw
=
new
HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
需要增加一下方法,要不会报错
需增加的一个方法
public
override
void
VerifyRenderingInServerForm( Control control )
{}
查看全文
相关阅读:
[Swift]LeetCode930. 和相同的二元子数组 | Binary Subarrays With Sum
[Swift]LeetCode929. 独特的电子邮件地址 | Unique Email Addresses
[Swift实际操作]八、实用进阶-(10)使用Swift创建一个二叉树BinaryTreeNode
[Swift]LeetCode5. 最长回文子串 | Longest Palindromic Substring
[Swift]LeetCode4. 两个排序数组的中位数 | Median of Two Sorted Arrays
[Swift]LeetCode3. 无重复字符的最长子串 | Longest Substring Without Repeating Characters
[Swift]LeetCode913.猫与老鼠 | Cat and Mouse
[Swift]LeetCode916.单词子集 | Word Subsets
[Swift]LeetCode915.将分区数组分成不相交的间隔 | Partition Array into Disjoint Intervals
OpenJDK源码研究笔记(十六):在Java中使用JavaScript脚本语言
原文地址:https://www.cnblogs.com/nonsuch/p/1103990.html
最新文章
宝塔上传大文件
ueditor+flash粘贴word
java上传文件夹文件
java+web+下载断点续传
文件的上传和下载
asp.net+大文件上传
vue上传大文件控件
linux 命令之 ping
atitit.插件体系设计总结o73.doc
ListView中pointToPosition()方法使用具体演示样例
热门文章
漫谈程序猿系列:怎么告别“混日子”
dp解Codeforces Round #260 (Div. 2)C. Boredom
UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
[2011山东ACM省赛] Sequence (动态规划)
nefu 118 n!后面有多少个0 算数基本定理,素数分解
php 、asp、 java、 c#、 delphi之间的语言对照
【ASP.NET】——AdRotator控件
win版本对比
Redis 笔记与总结1 安装部署
[Swift]LeetCode931. 下降路径最小和 | Minimum Falling Path Sum
Copyright © 2011-2022 走看看