[CustomAuthorize]
        public FileResult ExportQuestionCenterWord(SearchBaseQuestion search)
        {
            StringWriter strWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);
            StringBuilder sb = null;
            string html = "";

try
            {
                search.PageSize = Int32.MaxValue;
                search.Status = DeleteMarkEnum.Active;
                search.isAnswer = IsAnswerEnum.Total;
                search.isReview = IsReviewEnum.Total;
                search.AddOrderBy("MODIFYDATE", SearchOrderType.Desc);
                
                if (search.SOURCE == "0")
                    search.SOURCE = "";
                if (search.MODULE == "0")
                    search.MODULE = "";
                if (search.QUESTIONTYPE == "0")
                    search.QUESTIONTYPE = "";
                if (search.QSTATUS == "0")
                    search.QSTATUS = "";
                if (search.ADMINID == "0")
                    search.ADMINID = "";
                if (!string.IsNullOrEmpty(search.IsSaleQuestion) && search.IsSaleQuestion == "1")
                    search.CUSTOMERMANAGERIDs = GetInPermissionCustomerMannagerIDs();
                 
                IList<BASE_QUESTION> baseQuestionList = questionManager.SearchQuestionList(search);

IList<BASE_CHOICECUSTOMERMANAGER> managerList = customerManagerService.GetChoiceCusManageList();
                SearchChoiceCusManager search_msg = new SearchChoiceCusManager();
                search_msg.SearchType = SearchTypeEnum.Total;
                search_msg.Status = DeleteMarkEnum.Active;
                search_msg.parentIdMany = "samedatakefu";
                IList<BASE_CHOICECUSTOMERMANAGER> choiceManagerList = choiceCusManagerManager.Search(search_msg);

if (baseQuestionList.Count > 0)
                {
                    foreach (var baseQuestion in baseQuestionList)
                    {
                        //获取受理人
                        string ADMINID_Str = "";
                        if (choiceManagerList != null && choiceManagerList.Count > 0)
                        {
                            BASE_CHOICECUSTOMERMANAGER em = choiceManagerList.Where(m => m.USERID == baseQuestion.ADMINID).FirstOrDefault();
                            if (em != null)
                            {
                                ADMINID_Str = em.NAME;
                            }
                        }
                        BASE_CHOICECUSTOMERMANAGER manager = managerList.FirstOrDefault(t => t.ID == baseQuestion.CUSTOMERMANAGERID);

string strSource = string.Empty;
                        switch (baseQuestion.SOURCE)
                        {
                            case 1:
                                strSource = "QQ";
                                break;
                            case 2:
                                strSource = "Email";
                                break;
                            case 3:
                                strSource = "Online";
                                break;
                            case 4:
                                strSource = "Sales";
                                break;
                            case 5:
                                strSource = "用户直通车";
                                break;
                            case 6:
                                strSource = "需求直通车";
                                break;
                            case 7:
                                strSource = "回访";
                                break;
                            case 8:
                                strSource = "QQ群";
                                break;
                            case 9:
                                strSource = "社区";
                                break;
                            case 10:
                                strSource = "微信群";
                                break;
                            default:
                                strSource = "全部";
                                break;
                        }

sb = new StringBuilder();
                        sb.Append("<table border='1' cellspacing='0' style=\"width;1200px;\">");
                        sb.Append("<tbody>");
                        //第一行
                        sb.Append("<tr align='center'>");
                        sb.Append("<td colspan='3' style='width:1200px;'>");
                        sb.Append(baseQuestion.TITLE == null ? StringConst.NAConst : baseQuestion.TITLE);
                        sb.Append("</td>");
                        sb.Append("</tr>");

//第二行
                        BASE_USER user = userManager.GetUserByUniqueId(baseQuestion.USERID);
                        if (user == null)
                            user = new BASE_USER();

sb.Append("<tr>");
                        sb.Append("<td style='width:400px;'>");
                        sb.Append("姓名:" + user.REALNAME);
                        sb.Append("</td>");

sb.Append("<td style='width:400px;'>");
                        sb.Append("账号:" + baseQuestion.USERNAME);
                        sb.Append("</td>");

sb.Append("<td style='width:400px;'>");
                        sb.Append("联系方式:" + baseQuestion.MOBILE);
                        sb.Append("</td>");
                        sb.Append("</tr>");

//第三行
                        sb.Append("<tr>");
                        sb.Append("<td style='width:400px;'>");
                        sb.Append("模块:" + (string.IsNullOrEmpty(baseQuestion.MODULE) ? "" : packageTreeCopy.GetOneById(baseQuestion.MODULE) == null ? "" : packageTreeCopy.GetOneById(baseQuestion.MODULE).FULLNAME));
                        sb.Append("</td>");

sb.Append("<td style='width:400px;'>");
                        sb.Append("问题类型:" + AttributesUtils.GetEnumDescription<QuestionCenterTypeEnum>(baseQuestion.QUESTIONTYPE));
                        sb.Append("</td>");

sb.Append("<td style='width:400px;'>");
                        sb.Append("状态:" + AttributesUtils.GetEnumDescription<QuestionCenterStatusEnum>(baseQuestion.STATUS));
                        sb.Append("</td>");
                        sb.Append("</tr>");

//第四行
                        sb.Append("<tr>");
                        sb.Append("<td style='width:400px;'>");
                        sb.Append("受理人:" + ADMINID_Str);
                        sb.Append("</td>");

sb.Append("<td style='width:400px;'>");
                        sb.Append("产品对接人:" + baseQuestion.PRODUCTMANAGERNAME);
                        sb.Append("</td>");

sb.Append("<td style='width:400px;'>");
                        sb.Append("下次跟踪时间:" + (baseQuestion.NEXTVIEWDATE.ToString() == "0001-01-01 00:00:00" ? "" : baseQuestion.NEXTVIEWDATE.ToString()));
                        sb.Append("</td>");
                        sb.Append("</tr>");

//第五行
                        sb.Append("<tr>");
                        sb.Append("<td style='width:400px;'>");
                        sb.Append("标签:" + baseQuestion.KEYWORD);
                        sb.Append("</td>");

sb.Append("<td colspan='2' style='width:800px;'>");
                        sb.Append("来源:" + strSource);
                        sb.Append("</td>");
                        sb.Append("</tr>");

//第六行
                        sb.Append("<tr'>");
                        sb.Append("<td colspan='3' style='width:1200px;'>");
                        sb.Append("内容:" + baseQuestion.CONTENT);
                        sb.Append("</td>");
                        sb.Append("</tr>");

//第七行
                        string questionID = baseQuestion.ID.ToString();
                        BASE_ANSWER answer = answerManager.GetAnswerByQuestionsID(questionID);
                        sb.Append("<tr'>");
                        sb.Append("<td colspan='3' style='width:1200px;'>");
                        sb.Append("回复:" + (answer == null ? "" : HtmlDecode(answer.CONTENT)));
                        sb.Append("</td>");
                        sb.Append("</tr>");

sb.Append("</tbody>");
                        sb.Append("</table>");

sb.Append("<br/>");
                        sb.Append("<br/>");

html += sb.ToString();
                    }

strWriter.Write(html);
                }
                else
                {
                    strWriter.WriteLine("没有数据!");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.Error("ExportQuestionCenterWord error:", ex);
                strWriter.WriteLine("导出出现问题:" + ex.Message);
            }

byte[] fileContents = Encoding.GetEncoding("gb2312").GetBytes("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"><body>" + strWriter.ToString() + "</body></html>");
            return File(fileContents, "application/vnd.ms-word", string.Format("{0}.doc", "问题中心" + DateTime.Now.Date.ToString("yyyyMMdd")));
        }

c# html 导出word的更多相关文章

  1. java 导出word 并下载

    记录一下导出操作 源码: /************ * 导出word 并下载 * @param id 房号记录编号 * ***********************/ @RequestMappin ...

  2. Asp.net通过模板(.dot/Html)导出Word,同时导出图片

    一.Office组件导出Word(服务器配置麻烦) 需要引用Office的DLL,在下文的附件中,不同的Offic版本用的不一样,虽然高级版本可以兼容低级的,不过,还是统一版本最好 贴上核心代码(转载 ...

  3. 导出Excel And 导出word

      <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx. ...

  4. 使用NPOI2.1.3.1版本导出word附带表格和图片

    原文:http://www.cnblogs.com/afutureBoss/p/4074397.html?utm_source=tuicool&utm_medium=referral 最近项目 ...

  5. Java使用velocity导出word

    效果展示: 使用word编辑好模板

  6. 【吉光片羽】MVC 导出Word的两种方式

    1.直接将Html转成Word.MVC自带FileResult很好用.Html中我们也可以嵌入自己的样式. html: <div id="target"> <st ...

  7. java导出word的6种方式(复制来的文章)

    来自: http://www.cnblogs.com/lcngu/p/5247179.html 最近做的项目,需要将一些信息导出到word中.在网上找了好多解决方案,现在将这几天的总结分享一下. 目前 ...

  8. 【MVC】 非常简单的页面导出 WORD, EXCEL方法

    [MVC] 页面导出 WORD, EXCEL 前端 js function output() { var para = new Object(); para.html = getHtml(" ...

  9. 网页内容导出word/excel的js代码

    IE设置: 工具-> Internet选项-> 安全->自定义级别-> 对没有标记安全级别的ActiveX控件进行初始化  设为启用! 1.导出word //指定区域导出到Wo ...

  10. MVC4 导出word

    添加程序包 DocX using System.IO;using Novacode; /// <summary> /// 导出Word /// </summary> publi ...

随机推荐

  1. iOS | 解决中文乱码

    在iOS开发中,多多少少的朋友在开发的过程中,测试数据的时候可能会碰到后台打印的时候不能正确的打印出正常的汉字,打印出一些影响判断的字符,经常需要查看数组中得元素是否是自己想要的,但是苹果并没有对直接 ...

  2. ios常用数据库、完美无缺

    直接copy过去就能用,我们不用再去造轮子,现在的xocod9.4更加人性化了,不用再添加依赖库,这点苹果你让我开始喜欢了,哈哈. 需要这兄弟拉进去的哈 下班标的1,2,3,4就是就截图的4个文件,没 ...

  3. Redis Sentinel 介绍

    Redis Sentinel   sentinel的功能: 监控:sentinel节点定期检测redis数据节点,其余sentinel节点是否可达. 通知:sentinel 节点会将故障转移结果通知给 ...

  4. keepalived+haproxy 安装配置

    1.安装配置keepalived 修改配置文件/etc/keepalived/keepalived.conf ! Configuration File for keepalived global_de ...

  5. Ubuntu之C++开发环境的搭建

    初学Linux,今天反复卸载与重装微软商店的Ubuntu好几次,终于解锁了在Ubuntu上搭建C++开发环境的正确姿势, 搭建了一个非常简单的开发环境:简单到什么地步呢?只是简单地配置了一下编辑器,安 ...

  6. centos7.3 vsftpd 多用户配置

    1. 安装vsftpd及pam认证服务软件 yum install vsftpd* -y yum install pam* libdb-utils libdb* --skip-broken -y #设 ...

  7. python教程(二)·条件语句

    条件语句一般用来判断给定的条件是否成立,根据结果来执行不同的代码,也就是说,有了条件语句,才可以根据不同的情况做不同的事,从而控制程序的流程. 布尔类型 前面说到数据类型的时候,其中有一种叫 &quo ...

  8. 教你阅读MSDN英文文档,迅速提升编程能力

    在教大家阅读英文文档之前,首先给大家明确一个概念.C#和.NET的区别? 有一定编程经验的同学应该多多少少知道这方面的概念,但是可能模糊,理解的不一定深刻.我在这里简单给出两者的基本定义: C#:仅仅 ...

  9. Java设计模式(9)——结构型模式之装饰模式(Decorator)

    一.概述 动态地给一个对象添加一些额外的职责.就增加功能来说, Decorator模式相比生成子类更为灵活.该模式以对客 户端透明的方式扩展对象的功能. UML简图 角色 在持有Component的引 ...

  10. WPF 为 PasswordBox 控件添加水印,最低级版

    原因也很直接,老板需要,一开始为TextBox发愁,就找了这个控件凑合用,至于版权什么的,内部工具也不卖钱,而且我不懂英文,也就无视了: Extended WPF Toolkit™ Community ...