• 如何用Aspose.Words.dll把World文档生成图片


    如何用Aspose.Words.dll把World文档生成图片

    1、 首先需要在Bin目录中添加Aspose.Words.dll的引用

    2、把你要转换成图片的World文件中需要替换的地方加上标记

    3、把World文件保存成xml文件的格式  

      

    4、 把xml文件用记事本打开把替换标记符左右的空格去掉

    5、开始写代码如下:

      /// <summary>
        /// 资格证书
        /// </summary>
        protected string CreateJJRZGZSBH()
        {
    
            DataTable dt_UserInfo = DbHelperSQL.Query("select J_JJRZGZSBH '经纪人资格证书编号',I_JYFMC '交易方名称',JJRZGZS '经纪人资格证书',* 
    from AAA_DLZHXXB where B_DLYX='
    " + ViewState["DLYX"].ToString() + "'").Tables[0];//获取用户信息, string strJJRZGZSBH = dt_UserInfo.Rows[0]["经纪人资格证书编号"].ToString();//经纪人资格证书编号 string strJYFMC = dt_UserInfo.Rows[0]["交易方名称"].ToString();//交易方名称 string strJJRZGZS = dt_UserInfo.Rows[0]["交易方名称"].ToString();//经纪人资格证书 DateTime ZSYXQ_QS = DateTime.Now; //得到当前时间 string year_QS = ZSYXQ_QS.Year.ToString();//年份 string month_QS = ZSYXQ_QS.Month.ToString();//月份 string day_QS = ZSYXQ_QS.Day.ToString();//日期 DateTime ZSYXQ_ZZ = ZSYXQ_QS.AddYears(2);//有限期截止时间,在当前有效期在延后两年 string year_ZZ = ZSYXQ_ZZ.Year.ToString();//年份 string month_ZZ = ZSYXQ_ZZ.Month.ToString();//月份 string day_ZZ = ZSYXQ_ZZ.Day.ToString();//日期 string ResourcePath = Server.MapPath("JJRZGZS_Path/JJRZGZS_Initial.xml");//经纪人资格证书模板服务器路径 string FileName = Guid.NewGuid().ToString(); string Paths = Server.MapPath("JJRZGZS_NewPath/") + FileName + ".xml";//拷贝后的文件目录、 string NewPaths = Server.MapPath("JJRZGZS_NewPath/COPY/") + FileName + ".xml";//保存后的目录 string SavingPath = "~/Web/JHJX/New2013/JJRZGZS_Temp/" + FileName + ".png";//存入路径 if (File.Exists(ResourcePath)) { File.Copy(ResourcePath, Paths, true); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Paths);//载入此XML XmlNodeList xnl = xmlDoc.GetElementsByTagName("w:t");//office xml word的Tag foreach (XmlNode xn in xnl) { if (xn.InnerXml == "PT_BH") { xn.InnerText = strJJRZGZSBH; } if (xn.InnerXml == "JYFMC") { xn.InnerXml = strJYFMC; } if (xn.InnerXml == "YYYY_QS") { xn.InnerXml = year_QS; } if (xn.InnerXml == "MM_QS") { xn.InnerXml = month_QS; } if (xn.InnerXml == "dd_QS") { xn.InnerXml = day_QS; } if (xn.InnerXml == "YYYY_ZZ") { xn.InnerXml = year_ZZ; } if (xn.InnerXml == "MM_ZZ") { xn.InnerXml = month_ZZ; } if (xn.InnerXml == "dd_ZZ") { xn.InnerXml = day_ZZ; } if (xn.InnerXml == "YYYY_PT") { xn.InnerXml = year_QS; } if (xn.InnerXml == "MM_PT") { xn.InnerXml = month_QS; } if (xn.InnerXml == "dd_PT") { xn.InnerXml = day_QS; } } xmlDoc.Save(NewPaths); if (File.Exists(NewPaths)) { Document doc = new Document(NewPaths); ImageSaveOptions iso = new ImageSaveOptions(SaveFormat.Png);//另存为PNG格式 iso.Resolution = 256; doc.Save(Server.MapPath(SavingPath), iso); } File.Delete(NewPaths); File.Delete(Paths); } return SavingPath; }
  • 相关阅读:
    SpringBoot学习笔记
    2021牛客多校第一场 I题(DP)
    CSS小结
    AOP小结
    IOC容器小结
    Educational Codeforces Round 56 (Rated for Div. 2) G题(线段树,曼哈顿距离)
    Codeforces Round #656 (Div. 3) E. Directing Edges(拓扑排序)
    Educational Codeforces Round 101 (Rated for Div. 2) E
    [FJOI2017]矩阵填数 (容斥原理)
    优秀代码样板收集计划(python)
  • 原文地址:https://www.cnblogs.com/wolipengbo/p/3081669.html
Copyright © 2020-2023  润新知