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模板填充数据来导出。