c# html 导出word

[CustomAuthorize]
        public FileResult ExportQuestionCenterWord(SearchBaseQuestion search)
        {
            StringWriter strWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);
            StringBuilder sb = null;
            string html = "";文章来源地址:https://www.yii666.com/article/764123.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>");文章来源地址https://www.yii666.com/article/764123.html网址:yii666.com<

//第四行
                        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>");文章地址https://www.yii666.com/article/764123.html

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>");网址:yii666.com

//第五行
                        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. c# html 导出word

  2. 网页导出成word文档的默认视图方式问题

  3. word模版另存为网页(*.htm,*.html),转为jsp页面并加入数据后导出成word

  4. java导出生成word

    最近做的项目,需要将一些信息导出到word中。在网上找了好多解决方案,现在将这几天的总结分享一下。目前来看,java导出word大致有6种解决方案:1:Jacob是Java-COM Bridge的缩写,它在Java与微软的COM组件之间构建一座桥梁。使用Jacob自带的DLL动态链接库,并通过JNI的方式实现了

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信图片_20190322181744_03.jpg

微信扫一扫打赏

请作者喝杯咖啡吧~

支付宝扫一扫领取红包,优惠每天领

二维码1

zhifubaohongbao.png

二维码2

zhifubaohongbao2.png