已经发过帖了,但是不成功!我的问题是将table输出成word,并且默认为横向。http://topic.csdn.net/u/20090720/16/8e9fce1b-ad18-43e0-8da0-e898e11ef381.html?seed=1774644390&r=58636650#r_58636650输出部分代码如下
Response.Clear();
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=custom.doc");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
HttpContext.Current.Response.Write(table);
HttpContext.Current.Response.End();
tw.Close();帮解决下200分都给他
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=""us-ascii""
<html>
<head>
<title>a</title><style>
<!--
/* Page Definitions */
@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><body><div class=3DSection1>";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=custom.doc");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<table><tr><td>1</td><td>11</td></tr><tr><td>2</td><td>21</td></tr></table>");
HttpContext.Current.Response.Write("</div></body></html>");
HttpContext.Current.Response.End();
<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>this.Page.Response.AddHeader("content-Type: ","application/msword);
this.Page.Response.AddHeader("Content-Disposition: ","attachment;filename="+name);
参考
<head>
<title>a</title>
<style>
<!--
/* Page Definitions */
@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><body ><div class=3DSection1 >
<table border='0' align='center'style='border-collapse:collapse'>
<tr>
<td align='center'>
<font size='5'><b>案 卷 目 录</b></font>
</td>
</tr>
</table>
<table border='1' cellpadding='0' cellspacing='0' align='center' style='width:938px;border-collapse:collapse'>
<tr>
<td align='center' colspan='2'><font size='3'><b>案 卷 号</b></font></td>
<td rowspan='2' style='width: 428px;height: 35px' align='center'>
<b>
<font size='3'>
题
名 </font></b> </td>
<td rowspan='2' align='center'>
<b>
<font size='3'>
年 度</font></b> </td>
<td rowspan='2' align='center'>
<b>
<font size='3'>
页 数</font></b> </td>
<td rowspan='2' align='center' style='width: 74px'><b>
<font size='3'>
期 限</font></b> </td>
<td rowspan='2' align='center' style='width: 58px'><b>
<font size='3'>
备 注</font></b> </td>
</tr>
<tr>
<td style='width: 97px; height: 34px;' align='center'><b>
<font size='3'>
档案室编</font></b> </td>
<td align='center' style='width: 71px; height: 34px;'><b>
<font size='3'>
档案馆编</font></b> </td>
</tr><tr>
<td align='center' style='width: 97px; height: 35px;'>
<font size=2>0002</font> </td>
<td align='center' style='width: 71px; height: 35px;'> </td>
<td align='center' rowspan='1' style='width: 428px; height: 35px;'>
<font size='2'>
科技档案2科技档案2科技档案2科技档案2科技档案2科技档案2科技档案2科技档案2科技档案2科技档案2</font></td>
<td align='center' rowspan='1' style='width: 76px; height: 35px;'>
2009 </td>
<td align='center' rowspan='1' style='width: 76px; height: 35px;'>
20 </td>
<td align='center' rowspan='1' style='width: 74px; height: 35px;'>
永久 </td>
<td align='center' rowspan='1' style='width: 58px; height: 35px;'>
科技档 </td>
</tr><tr>
<td align='center' style='width: 97px; height: 35px;'>
<font size=2>0003</font> </td>
<td align='center' style='width: 71px; height: 35px;'> </td>
<td align='center' rowspan='1' style='width: 428px; height: 35px;'> </td>
<td align='center' rowspan='1' style='width: 76px; height: 35px;'> </td>
<td align='center' rowspan='1' style='width: 76px; height: 35px;'> </td>
<td align='center' rowspan='1' style='width: 74px; height: 35px;'> </td>
<td align='center' rowspan='1' style='width: 58px; height: 35px;'> </td>
</tr></table></div></body></html>