zoukankan      html  css  js  c++  java
  • 根据word模板导出,替换

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using xyxx_base.Models;
    using istrong.db;
    using Aspose.Words;
    using System.IO;
    using System.Configuration;
    
    namespace xyxx_base.Common
    {
        public static class WordHelper
        {
            private readonly static DbHelper db = DbHelperFactory.GetDbHelper();
    
            public static string GetBidReport(TenderProject tp)
            {
                //专家名单
                string experts = "";
                foreach (var expert in tp.Experts)
                {
                    if (expert.IsLeader)
                    {
                        experts += expert.Name + "(主任)、";
                    }
                    else
                    {
                        experts += expert.Name + "";
                    }
                }
                experts = experts.Remove(experts.Count() - 1);//删除最后一个断号
                //获取中标候选人
                var tss = db.LinqQuery<TenderSignup>().Where(e => e.TpId == tp.Id && e.BidderOrder > 0).OrderBy(e => e.BidderOrder).ToList();
                var firstEntp = tss[0].UserEntpInfo.UserEntpName;
                var secondEntp = tss[1].UserEntpInfo.UserEntpName;
                var thirdEntp = tss[2].UserEntpInfo.UserEntpName;
    
                //获取总报名数,无效企业数
                var entpTotalCount = db.LinqQuery<TenderSignup>().Where(e => e.TpId == tp.Id && !e.IsRevoke).Count();
                var entpInvalidCount = db.LinqQuery<TenderSignup>().Where(e => e.TpId == tp.Id && !e.IsRevoke && (!e.IsEnter || !e.IsDecry || !e.IsSignup)).Count();
    
                //构成需要替换的字典
                var dict = new Dictionary<string, string>();
                dict["招标标题"] = tp.Title;
                dict["招标编号"] = tp.Detail.GetStringValue("招标编号");
                dict["招标人"] = tp.Detail.GetStringValue("招标人");
                dict["当前时间"] = DateTime.Now.ToString("yyyy年MM月dd日");
                dict["设备造价"] = tp.Detail.GetStringValue("设备造价");
                dict["地区"] = "福州市";
                dict["招标方式"] = tp.Detail.GetStringValue("招标方式");
                dict["交货期"] = tp.Detail.GetStringValue("交货期");
                dict["专家名单"] = experts;
                dict["总报名数"] = entpTotalCount.ToString();
                dict["无效企业"] = entpInvalidCount.ToString();
                dict["第一候选人"] = firstEntp;
                dict["第二候选人"] = secondEntp;
                dict["第三候选人"] = thirdEntp;
    
                string baseWay = System.AppDomain.CurrentDomain.BaseDirectory;
                Document doc = new Document(baseWay + "fjebid\template\common\评标报告模板.doc");
                foreach (var key in dict.Keys)
                {
                    var repStr = string.Format("&{0}&", key);
                    doc.Range.Replace(repStr, dict[key], true, false);
                }
    
                //保存
                string fileName = tp.Title + "评标报告" + ".doc";
    
                string currentTime = DateTime.Now.ToString("yyyy-MM");
                string fileWay = baseWay + "files\" + currentTime;
                if (!System.IO.File.Exists(fileWay))
                {
                    Directory.CreateDirectory(fileWay);
                }
    
                doc.Save(fileWay + "\" + fileName);
    
                return ConfigurationManager.AppSettings["Domain"] + "/files/" + currentTime + "/" + fileName;
    
            }
        }
    }
  • 相关阅读:
    开源软件架构总结之——Bash(readline做输入交互式,词法语法分析,进程交互)
    python——使用readline库实现tab自动补全
    声明式编程——抽象程度更高,关注是什么(what),而非如何做(how)
    splunk rest api search
    Elasticsearch单机下多实例配置
    splunk 通过rest http导入数据
    vnc xfce tab自动补全失效的解决方法
    止增笑耳星际前传
    [WPF]静态资源(StaticResource)和动态资源(DynamicResource)
    【 D3.js 入门系列 --- 3 】 做一个简单的图表!
  • 原文地址:https://www.cnblogs.com/ysf123/p/4380286.html
Copyright © 2011-2022 走看看