根据数据提供下载包含不同数据的word

1.实例化xml数据

static string ExportTemplate
    {
        get
        {
            if (__ExportTemplate == null)
            {
                string path = HttpContext.Current.Server.MapPath(Path.Combine("doc", "export.xml"));
                using (StreamReader sr = new StreamReader(path))
                {
                    __ExportTemplate = sr.ReadToEnd();
                    sr.Close();
                    sr.Dispose();
                }
            }
            return __ExportTemplate;
        }
    }

private static string __ExportTemplate = null;

2.写入xml数据方法

String toWriteTxt = ;//写入word的字符串

 // clear the current output content from the buffer
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=/"" + FileName + ".doc/""); 

 // 根据实际下载FileName修改,最好全部是英文
Response.ContentType = "application/octet-stream";
Response.Write(toWriteTxt);

Response.End();

 

3.动态加载

private String Export(String id)
    {
        /* 注释 */
        View_Mov_Export cfpc = new View_Mov_Export();
        cfpc.Load(string.Format("ID='{0}'", new Guid(id)));

        //特殊字符处理
        if(!string.IsNullOrEmpty(cfpc.ChineseName))
        {
        cfpc.ChineseName = cfpc.ChineseName.Replace("&", "&");
        }
        if (!string.IsNullOrEmpty(cfpc.EnglishName))
        {
            cfpc.EnglishName = cfpc.EnglishName.Replace("&", "&");
        }
        if (!String.IsNullOrEmpty(cfpc.OriginName))
        {
            cfpc.OriginName = cfpc.OriginName.Replace("&", "&");
        }
        if (!string.IsNullOrEmpty(cfpc.ProductionDirector))
        {
            cfpc.ProductionDirector = cfpc.ProductionDirector.Replace("&", "&");
        }
        if (!String.IsNullOrEmpty(cfpc.ProductionDirectorEN))
        {
            cfpc.ProductionDirectorEN = cfpc.ProductionDirectorEN.Replace("&", "&");
        }
        if (!string.IsNullOrEmpty(cfpc.AwardsHistory))
        {
            cfpc.AwardsHistory = cfpc.AwardsHistory.Replace("&", "&");
        } if (!string.IsNullOrEmpty(cfpc.ScreenWriter))
        {
            cfpc.ScreenWriter = cfpc.ScreenWriter.Replace("&", "&");
        }

        FileName = cfpc.SN;

        String toWriteTxt = ExportTemplate;

        if (!string.IsNullOrEmpty(cfpc.SN))
        {
            toWriteTxt = toWriteTxt.Replace("##SN##", cfpc.SN);
        }
        else
        {
            toWriteTxt = toWriteTxt.Replace("##SN##", string.Empty);
        }

        if (cfpc.PublishTime != null && cfpc.PublishTime != DateTime.MinValue)
        {
            toWriteTxt = toWriteTxt.Replace("Publishtime", cfpc.PublishTime.ToString("yyyy年M月"));
        }
        else
        {
            toWriteTxt = toWriteTxt.Replace("Publishtime", string.Empty);
        }

        //if (cfpc.FirstShowDate != null)
        //    toWriteTxt = toWriteTxt.Replace("FirstShowDate", cfpc.FirstShowDate.ToString("yyyy年MM月dd日"));
        //else
        if (string.IsNullOrEmpty(cfpc.Length.ToString()) || cfpc.Length < 0)
            toWriteTxt = toWriteTxt.Replace("FirstShowDate", "0 分钟");
        else
            toWriteTxt = toWriteTxt.Replace("FirstShowDate", cfpc.Length.ToString() + " 分钟");

        if (!string.IsNullOrEmpty(cfpc.Category))
            toWriteTxt = toWriteTxt.Replace("Category", getDisplayName(cfpc.Category, "SIFF_Basic_Category"));
        else
            toWriteTxt = toWriteTxt.Replace("Category", string.Empty);
        //Nature: todo
        /*
         *
         *
         *
         * **/
        if (!string.IsNullOrEmpty(cfpc.OriginName))
            toWriteTxt = toWriteTxt.Replace("OriginName",cfpc.OriginName);
        else
            toWriteTxt = toWriteTxt.Replace("OriginName", string.Empty);
        if (!string.IsNullOrEmpty(cfpc.EnglishName))
            toWriteTxt = toWriteTxt.Replace("EnglishName", cfpc.EnglishName);
        else
            toWriteTxt = toWriteTxt.Replace("EnglishName", string.Empty);
        if (!string.IsNullOrEmpty(cfpc.ChineseName))
            toWriteTxt = toWriteTxt.Replace("ChineseName", cfpc.ChineseName);
        else
            toWriteTxt = toWriteTxt.Replace("ChineseName", string.Empty);

        if (!string.IsNullOrEmpty(cfpc.Country))
            toWriteTxt = toWriteTxt.Replace("ProducerCountry", getDisplayName(cfpc.Country, "SIFF_Country"));
        else
            toWriteTxt = toWriteTxt.Replace("ProducerCountry", string.Empty);

        StringBuilder sbCoCountries = new StringBuilder();

        if (!string.IsNullOrEmpty(cfpc.CoCountry) )
        {
            string[] countries = cfpc.CoCountry.Split(',');
            if (countries.Length != 0)
            {
                foreach (string country in countries)
                {
                    sbCoCountries.Append(getDisplayName(country, "SIFF_Country") + ",");
                }
                toWriteTxt = toWriteTxt.Replace("ProducercoCountry", sbCoCountries.ToString().Substring(0, sbCoCountries.ToString().Length - 1));
            }
            else
            {
                toWriteTxt = toWriteTxt.Replace("ProducercoCountry", string.Empty);
            }
        }
        else
        {
            toWriteTxt = toWriteTxt.Replace("ProducercoCountry", string.Empty);
        }

        toWriteTxt = toWriteTxt.Replace("ColorInfo", getDisplayName(cfpc.Color, "SIFF_Technique_Color")).Replace("AwardsHistory", cfpc.AwardsHistory);
        toWriteTxt = toWriteTxt.Replace("SHShowType", getDisplayName(cfpc.SHShowType, "SIFF_Basic_SHShowType"));
        //获得编剧名称: 优先显示中文名称,中文名称不存在,则显示相应的英文
        if (!string.IsNullOrEmpty(cfpc.ScreenWriter))
        {
            toWriteTxt = toWriteTxt.Replace("ScreenWriter", cfpc.ScreenWriter.Split('$')[0]);
        }
        else
        {
            if (!string.IsNullOrEmpty(cfpc.ScreenWriterEN))
            {
                toWriteTxt = toWriteTxt.Replace("ScreenWriter", cfpc.ScreenWriterEN.Split('$')[0]);
            }
            else
            {
                toWriteTxt = toWriteTxt.Replace("ScreenWriter", string.Empty);
            }
        }

        /*
        if (!string.IsNullOrEmpty(cfpc.ScreenWriterEN)  && !string.IsNullOrEmpty(cfpc.ScreenWriter))
            toWriteTxt = toWriteTxt.Replace("ScreenWriter", cfpc.ScreenWriterEN.Split('$')[0] + "、" + cfpc.ScreenWriter.Split('$')[0]);
        else if (!string.IsNullOrEmpty(cfpc.ScreenWriterEN))
            toWriteTxt = toWriteTxt.Replace("ScreenWriter", cfpc.ScreenWriterEN.Split('$')[0]);
        else if (!string.IsNullOrEmpty(cfpc.ScreenWriter))
            toWriteTxt = toWriteTxt.Replace("ScreenWriter", cfpc.ScreenWriter.Split('$')[0]);
        else
            toWriteTxt = toWriteTxt.Replace("ScreenWriter", string.Empty);
         * */
        //摄影人名称:优先显示中文名称,中文名称不存在,则显示相应的英文
        if (!string.IsNullOrEmpty(cfpc.Cameraman))
        {
            toWriteTxt = toWriteTxt.Replace("Cameraman", cfpc.Cameraman.Split('$')[0]);
        }
        else
        {
            if (!string.IsNullOrEmpty(cfpc.CameramanEN))
            {
                toWriteTxt = toWriteTxt.Replace("Cameraman", cfpc.CameramanEN.Split('$')[0]);
            }
            else
            {
                toWriteTxt = toWriteTxt.Replace("Cameraman", string.Empty);
            }

        }
        /*
        if (!string.IsNullOrEmpty(cfpc.CameramanEN ) && !string.IsNullOrEmpty(cfpc.Cameraman ))
            toWriteTxt = toWriteTxt.Replace("Cameraman", cfpc.CameramanEN.Split('$')[0] + "、" + cfpc.Cameraman.Split('$')[0]);
        else if (!string.IsNullOrEmpty(cfpc.CameramanEN))
            toWriteTxt = toWriteTxt.Replace("Cameraman", cfpc.CameramanEN.Split('$')[0]);
        else if (!string.IsNullOrEmpty(cfpc.Cameraman) )
            toWriteTxt = toWriteTxt.Replace("Cameraman", cfpc.Cameraman.Split('$')[0]);
        else
            toWriteTxt = toWriteTxt.Replace("Cameraman", string.Empty);
         * */
        //音乐人名称:优先显示中文名称,中文名称不存在,则显示相应的英文
        if (!string.IsNullOrEmpty(cfpc.Musician))
        {
            toWriteTxt = toWriteTxt.Replace("Musician", cfpc.Musician.Split('$')[0]);
        }
        else
        {
            if (!string.IsNullOrEmpty(cfpc.MusicianEN))
            {
                toWriteTxt = toWriteTxt.Replace("Musician", cfpc.MusicianEN.Split('$')[0]);
            }
            else
            {
                toWriteTxt = toWriteTxt.Replace("Musician", string.Empty);
            }
        }
        /*
        if (!string.IsNullOrEmpty(cfpc.MusicianEN ) && !string.IsNullOrEmpty(cfpc.Musician ))
            toWriteTxt = toWriteTxt.Replace("Musician", cfpc.MusicianEN.Split('$')[0] + "、" + cfpc.Musician.Split('$')[0]);
        else if (!string.IsNullOrEmpty(cfpc.MusicianEN))
        {
            toWriteTxt = toWriteTxt.Replace("Musician", cfpc.MusicianEN.Split('$')[0]);
        }
        else if (!string.IsNullOrEmpty(cfpc.Musician) )
            toWriteTxt = toWriteTxt.Replace("Musician", cfpc.Musician.Split('$')[0]);
        else
            toWriteTxt = toWriteTxt.Replace("Musician", string.Empty);
        */
        //Nature
        string[] natures = cfpc.Nature.Split(',');
        String NatureShow = string.Empty;
        if (cfpc.Nature.Contains("GJDYZY"))
        {
            toWriteTxt = toWriteTxt.Replace("Nature2", "是");

        }
        else
        {
            toWriteTxt = toWriteTxt.Replace("Nature2", "否");
        }

        foreach (string str in natures)
        {
            //if (str != "GJDYZY")
            //{
            NatureShow += getDisplayName(str, "SIFF_Basic_Nature") + ",";
            //}
        }

        try
        {
            toWriteTxt = toWriteTxt.Replace("Nature1", NatureShow.Substring(0, NatureShow.Length - 1));
        }
        catch (Exception)
        {
            toWriteTxt = toWriteTxt.Replace("Nature1", string.Empty);
        }

        //导入制片信息:优先显示中文名称,中文名称不存在,则显示相应的英文

        toWriteTxt = getProducerInfo(id, toWriteTxt);


        //导入演员信息
        toWriteTxt = getActors(id, toWriteTxt);

        //导出导演信息:优先显示中文名称,中文名称不存在,则显示相应的英文
        DataTable dtDirector = DataAccess.Select(typeof(Mov_Participant_Director), string.Format("ID='{0}'", id));
        if (dtDirector.Rows.Count == 0)
        {
            toWriteTxt = toWriteTxt.Replace("DirectorName", string.Empty);
            toWriteTxt = toWriteTxt.Replace("DYB", string.Empty);
        }
        else if (dtDirector.Rows.Count >0 )
        {
            if (!string.IsNullOrEmpty(dtDirector.Rows[0]["Name"].ToString()))
            {
                toWriteTxt = toWriteTxt.Replace("DirectorName", dtDirector.Rows[0]["Name"].ToString().Split('$')[0]);

            }
            else
            {
                if (!string.IsNullOrEmpty(dtDirector.Rows[0]["NameEn"].ToString()))
                {
                    toWriteTxt = toWriteTxt.Replace("DirectorName", dtDirector.Rows[0]["NameEn"].ToString().Split('$')[0]);

                }
                else
                {
                    toWriteTxt = toWriteTxt.Replace("DirectorName", string.Empty);
                }
            }
           // toWriteTxt = toWriteTxt.Replace("DirectorName", dtDirector.Rows[0]["NameEn"].ToString().Split('$')[0] + "、" + dtDirector.Rows[0]["Name"].ToString().Split('$')[0]);
            toWriteTxt = toWriteTxt.Replace("DYB", getDisplayName(dtDirector.Rows[0]["Number"].ToString(), "SIFF_Participant_Number"));
        }
        //由于评定级别中有一个级别包含"&",所以不能直接替换,只需要把用户输入的字段进行处理。
        //return toWriteTxt.Replace("&", "&amp;");
        return toWriteTxt;

    }

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值