已经发过帖了,但是不成功!我的问题是将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分都给他

解决方案 »

  1.   

     string strHTML = @"MIME-Version: 1.0
    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();
      

  2.   

    我是table不是网页 你这样弄 输出的word我打不开 提示该文件不是单个网页什么的
      

  3.   

    我这个就是输出的table.并且测试成功的.你先保存到本地,然后打开看看,另:你的word什么版本的?
      

  4.   

    <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>this.Page.Response.AddHeader("content-Type: ","application/msword); 
    this.Page.Response.AddHeader("Content-Disposition: ","attachment;filename="+name); 
    参考
      

  5.   

    按照慕白大哥地方法输出的word默认还是纵向啊!以下是输出的html,请审查<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 >
        <table border='0' align='center'style='border-collapse:collapse'>
        <tr>
        <td align='center'>
        <font size='5'><b>案 &nbsp;&nbsp;&nbsp;  卷 &nbsp; &nbsp; 目 &nbsp; &nbsp; 录</b></font>
        </td>
        </tr>
        </table>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            
        <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>案&nbsp; &nbsp;卷 &nbsp; 号</b></font></td>
            <td rowspan='2' style='width: 428px;height: 35px' align='center'>
    <b>
            <font size='3'>
                题 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                名        </font></b>    </td>
           <td rowspan='2' align='center'>
    <b>
           <font size='3'>
               年 &nbsp; 度</font></b>    </td>
           <td rowspan='2' align='center'>
    <b>
           <font size='3'>
               页 &nbsp; 数</font></b>    </td>
           <td rowspan='2' align='center' style='width: 74px'><b>
           <font size='3'>
               期 &nbsp; 限</font></b>    </td>
           <td rowspan='2' align='center' style='width: 58px'><b>
           <font size='3'>
               备 &nbsp; 注</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;'>&nbsp;
      <font size=2>0002</font>                </td>
                <td align='center' style='width: 71px; height: 35px;'>&nbsp;            </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;'>&nbsp;
      <font size=2>0003</font>                </td>
                <td align='center' style='width: 71px; height: 35px;'>&nbsp;</td>
              <td align='center' rowspan='1' style='width: 428px; height: 35px;'>&nbsp;</td>
              <td align='center' rowspan='1' style='width: 76px; height: 35px;'>&nbsp;</td>
              <td align='center' rowspan='1' style='width: 76px; height: 35px;'>&nbsp;</td>
              <td align='center' rowspan='1' style='width: 74px; height: 35px;'>&nbsp;</td>
              <td align='center' rowspan='1' style='width: 58px; height: 35px;'>&nbsp;</td>
            </tr></table></div></body></html>
      

  6.   

    wuyq11 的看到了 貌似找到问题了 试验下
      

  7.   

    Section1 部分要对迎上 谢谢慕白和如梦兄 结贴给分
      

  8.   

    如果前面不用MIME就不要3D,