代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.NET
】
html横向导入word
作者:
新凡
/ 发布于
2016/8/26
/
831
导入word事件 /// <summary> /// 导入word事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btuDaoWord_ServerClick(object sender, EventArgs e) { StringBuilder html = new StringBuilder(); TenderNoticeEntity etyTenderNotice = new TenderNoticeEntity(); etyTenderNotice = _busTenderNotice.SearchId(hdCID.Value); if (etyTenderNotice != null) { html.Append(@" <html> <head> <style> .t1{background:URL('" + System.Configuration.ConfigurationManager.AppSettings.Get("ImgFilePath").ToString() + @"/images/shuiyin.png');position:absolute;filter:alpha(opacity=10);z-index:1; width:100%; height:100%} .t2{z-index:2; width:100%; height:100%;position:absolute} .table7 { font-size:14pt; border-top: 1px solid #000000; border-left: 1px solid #000000; } .table7 th { font-size:14pt; font-weight:lighter ; } .tabletd { font-size:14pt; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; padding-left:5px; padding-right:5px; } #gvContractDetail { border-top: 1px solid #000000; border-left: 1px solid #000000; border-bottom: 1px solid #000000; border-right: 1px solid #000000; } #gvContractDetail th { border-top: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; line-height: 50px; font-weight:lighter ; } #gvContractDetail td { border-top: 1px solid #000000; border-left: 1px solid #000000; line-height: 50px; } .p1 { margin: 0px; padding: 0px; height: 25px; line-height: 50px; font-size:14pt; } <!-- @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page WordSection1 {size:841.9pt 595.3pt; mso-page-orientation:landscape; margin:89.85pt 72.0pt 89.85pt 72.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.WordSection1 {page:WordSection1;} --> </style> </head> <body style=""background:URL('" + System.Configuration.ConfigurationManager.AppSettings.Get("ImgFilePath").ToString() + @"/images/shuiyin2.png');position:absolute;""> <div class=""t1""></div> <div class=""WordSection1""> <table cellspacing=""4"" cellpadding=""0"" width=""100%"" Height=""100%"" align=""center"" border=""0""> <tr> <td> <p align=""center"" style=""margin: 0px; padding: 0px; font-size:30pt;""> <strong>中 标 通 知 书</strong> <p align=""right"" style=""margin: 0px; padding: 0px; font-size:14pt;""> 招标编号:" + etyTenderNotice.Tendernum + @" <table cellspacing=""0"" cellpadding=""0"" width=""100%"" Height=""80%"" align=""center""> <tr style="" height:100%""> <td style=""height: 25px;"" align=""right"" valign=""top"" width=""48%"" class=""tabletd""> <p align=""left"" class=""p1"" style=""padding-top:10px;""> <u> " + etyTenderNotice.Successtenderdept + @" </u>: <p class=""p1"" align=""left""> <span align=""left""> </span><u>潞安环保能源开发股份有限公司:" + etyTenderNotice.TenderPeopleName + @" </u> (招标人名称)的<u> " + etyTenderNotice.Tendername + @" </u>(招标项目名称)于<u> " + etyTenderNotice.Tenderdate.ToString("yyyy年MM月dd日") + @" </u> 开标后,已完成评标工作,确定你单位下列设备(材料)中标: <div> <table cellspacing=""0"" rules=""all"" border=""1"" id=""gvContractDetail"" style=""width:100%;border-collapse:collapse;""> <tr align=""center""> <th scope=""col"">序号</th><th scope=""col"">名称</th><th scope=""col"">规格型号</th><th scope=""col"">数量</th><th scope=""col"">金额(万元)</th> </tr>"); DataTable dt = _busTenderNoticeDetails.Search(new TenderNoticeDetailsEntity() { Id = etyTenderNotice.Tendernoticeid }).Tables[0]; foreach (DataRow dr in dt.Rows) { html.Append(@" <tr align=""center""> <td>" + dr["PlanOrder"] + @"</td><td>" + dr["MachineName"] + @"</td><td>" + dr["MachineNum"] + @"</td><td>" + dr["GZSL"] + @"</td><td>" + dr["GZJE"] + @"</td> </tr>"); } html.Append(@" </table> </div> </td> <td valign=""top""> </td> <td valign=""top"" class=""tabletd"" width=""48%"" > <span> </span> <p class=""p1""> 中标总价<u> " + DataConvert.ConvertSum((DataConvert.ToDecimal(etyTenderNotice.Successtenderprice) * 10000).ToString("0")) + @" (大写) </u>万元, 请贵单位收到中标通知书后,在<u>" + etyTenderNotice.Lastdate.ToString("yyyy年MM月dd日") + @"</u>前持中标通知书与招标人进行合同谈判与签订。 <span> </span> <p class=""p1""> 招标人(盖章) 潞安集团招标领导组 办公室(备案) <span> </span> <p class=""p1"" align=""right""> " + etyTenderNotice.SendDate.ToString("yyyy年MM月dd日") + @" </td> </tr> </table> <div style=""padding-top:10px;""></div> <span style=""font-size: 10pt;height: 15px;line-height: 15px;"">备注:<span>1.</span>此中标通知书一式三份,招标人、中标人、集团公司招标办公室各一份。</span> <span style=""font-size: 10pt;""> 2.设备(材料)种类、项目过多超出表格时,可采用附页填报并加盖公章。</span> </td> </tr> </table> </div> </body> </html> "); } Tools.ToWord(html); Response.End(); } C#导入word方法: //************************************************************************************************ /// <summary> /// 将控件内容导出到Excel,传递一个控件 /// </summary> /// <param name="body">控件名称</param> public static void ToDocument(StringBuilder str) { //清除Response缓存内容 HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; //确定字符的编码格式 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Document.xls"); HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword HttpContext.Current.Response.Charset = "GB2312"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //表体空间 // System.IO.StringWriter swBody = new System.IO.StringWriter(); // System.Web.UI.HtmlTextWriter hwBody = new System.Web.UI.HtmlTextWriter(swBody); // body.RenderControl(hwBody); //消除乱码特别设定,非常规方法 string strExcel = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">"; //strExcel += hwBody.InnerWriter.ToString(); HttpContext.Current.Response.Write(strExcel + str); HttpContext.Current.Response.End(); } //************************************************************************************************ /// <summary> /// 将控件内容导出到word,传递一个控件 /// </summary> /// <param name="body">控件名称</param> public static void ToWord(StringBuilder str) { //清除Response缓存内容 HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; //确定字符的编码格式 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Document.doc"); HttpContext.Current.Response.ContentType = "application/msword";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword HttpContext.Current.Response.Charset = "GB2312"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //表体空间 // System.IO.StringWriter swBody = new System.IO.StringWriter(); // System.Web.UI.HtmlTextWriter hwBody = new System.Web.UI.HtmlTextWriter(swBody); // body.RenderControl(hwBody); //消除乱码特别设定,非常规方法 string strExcel = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">"; //strExcel += hwBody.InnerWriter.ToString(); HttpContext.Current.Response.Write(strExcel + str); HttpContext.Current.Response.End(); } 首先在页面的head中加下面的一段代码 <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style> <!-- @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:841.9pt 595.3pt; mso-page-orientation:landscape; margin:89.85pt 72.0pt 89.85pt 72.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} --> </style> </head> 然后用div包含整个的显示内容,会调用上面的style <div class=Section1> </div>
试试其它关键字
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
新凡
贡献的其它代码
(
10
)
.
微信公众号去除分享菜单
.
清除IE10下input的叉叉(X)和密码输入框的眼睛图标
.
只能输入汉字
.
html横向导入word
.
颜色选择框
.
使用smtp库发送邮件
.
用于给页面中添加事件
.
Nginx反向代理-根据域名反向代理
.
修改input的type属性问题
.
清除radio单选框外边距
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3