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);

 

上一篇:51单片机实战教程(34 线缆摇摆测试机设计)


下一篇:Java实现word转pdf