编程语言
首页 > 编程语言> > aspose.word 替换图片

aspose.word 替换图片

作者:互联网

需求:

把模版文件中的图片替换为其它的图片

 

 //模版
            string path = Server.MapPath("/yjz/261.doc");
            //图片
            string path2 = Server.MapPath("/yjz/sign.png");
            //保存文件
            string path3 = Server.MapPath("/") + "/yjz/261temp.doc";
            Document doc = new Document(path);
            //DocumentBuilder builder = new DocumentBuilder(doc);
            NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
            foreach (Aspose.Words.Drawing.Shape nshape in shapes)
            {
                /*
                 AlternativeText:这个属性,在操作模板时 ,与插入的图片文件名称一致
                 */
                //Console.WriteLine(nshape.AlternativeText); 
                imgdata.Add(nshape.AlternativeText);
                nshape.ImageData.SetImage(path2);
                /*
                switch (nshape.AlternativeText)
                {
                    case "img1":
                        nshape.ImageData.SetImage(@"d:img3.png");
                        break;
                    case "img2":
                        nshape.ImageData.SetImage(@"d:img4.png");
                        break;
                }
                */
            }

            doc.Save(path3);

 

标签:AlternativeText,word,string,ImageData,SetImage,doc,aspose,nshape,替换
来源: https://www.cnblogs.com/gxivwshjj/p/15406044.html