导入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>
<p align=""right"" style=""margin: 0px; padding: 0px; font-size:14pt;"">
招标编号:" + etyTenderNotice.Tendernum + @"
</p>
<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>
<br />
<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>
开标后,已完成评标工作,确定你单位下列设备(材料)中标:
</p>
<br />
<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%"" >
<p>
<span> </span>
</p>
<p class=""p1"">
中标总价<u> " + DataConvert.ConvertSum((DataConvert.ToDecimal(etyTenderNotice.Successtenderprice) * 10000).ToString("0")) + @" (大写) </u>万元,
请贵单位收到中标通知书后,在<u>" + etyTenderNotice.Lastdate.ToString("yyyy年MM月dd日") + @"</u>前持中标通知书与招标人进行合同谈判与签订。
</p>
<p>
<span> </span>
</p>
<p class=""p1"">
招标人(盖章) 潞安集团招标领导组<br>
办公室(备案)
</p>
<p>
<span> </span>
</p>
<p class=""p1"" align=""right"">
" + etyTenderNotice.SendDate.ToString("yyyy年MM月dd日") + @"
<br>
</p>
</td>
</tr>
</table>
<div style=""padding-top:10px;""></div>
<span style=""font-size: 10pt;height: 15px;line-height: 15px;"">备注:<span>1.</span>此中标通知书一式三份,招标人、中标人、集团公司招标办公室各一份。</span>
<br>
<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();
}
今天一直在弄横向导入word
在网上收了收主要就是通过css样式把要导入的html设置为横向的
首先在页面的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>