简单的C#导出word(一)

 StringBuilder builder = new StringBuilder();
            //builder.Append("<meta http-equiv=\"content-type\" content=\"application/ms-word; charset=UTF-8\"/>");
            builder.Append("<table border='0' cellspacing='0' cellpadding='0' style='text-align:center;width:100%;font-size:large'><tr><td><b>标题</b></td></tr></table>");
            builder.Append("<table style='text-align:center;width:100%' border='1'cellspacing='0' cellpadding='0'  >");
            builder.Append("           <tr style='height:40px'><td>承办单位</td>");
            builder.Append("<td colspan='3'></td></tr>");
            builder.Append("            <tr style='height:40px'><td style='width:20%;'>交办日期</td>");
            builder.Append("<td style='width:30%;'></td>");
            builder.Append("               <td style='width:20%;'>传真电话</td>");
            builder.Append("               <td style='width:30%;'>0371-66309213</td></tr>");
            builder.Append("           <tr style='height:40px'><td>交办期限</td>");
            builder.Append("               <td></td>");
            builder.Append("               <td>监察总队邮箱</td>");
            builder.Append("               <td>hn12369@163.com</td></tr>");
            builder.Append("           <tr style='height:40px'><td>编号 </td>");
            builder.Append("           <td colspan='3'></td></tr>");
            builder.Append("            <tr style='height:500px'><td>环境咨询<br />投诉内容</td><td colspan='3' style='text-align:left;'>");
            builder.Append("留言标题:" + lbl_Title.Text + "<br/>");
            builder.Append("留言时间:" + lbl_ComplainTime.Text + "<br/>");
            builder.Append("留言内容:" + txt_QuizContent.Text + "<br/>");
            builder.Append("留言人姓名:" + lbl_Person.Text + "<br/>");
            builder.Append("留言人电子邮箱:" + model.QuizEmail + "<br/>");
            builder.Append("是否愿意公开:" + lbl_Issue.Text + "<br/>");
            builder.Append("留言人所在地区:" + lbl_Region.Text + "<br/>");
            builder.Append("留言人电话:" + model.QuizTel);
            builder.Append("            </td></tr>");
            builder.Append("           <tr style='height:60px'><td>服务大厅<br />意  见</td>");
            builder.Append("               <td colspan='3'></td></tr>");
            builder.Append("          <tr style='height:40px'><td>备注</td>");
            builder.Append("              <td colspan='3'></td> </tr>");
            builder.Append("      </table>");
            
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=myword.doc");
            Response.ContentType = "application/ms-word";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Write(builder);
            
            Response.End();


上面就是简单地word导出的一种方法是吧html表格导出成word这种方法比较好理解,但是后期维护比较麻烦。

还有一种方法就是用Word模板填充数据来导出。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值