zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    IO流
    异常,File,递归,IO流
    Collection接口 map
    使用canvas画出的时钟
    js对象2
    js对象
    js 猜数游戏、斗地主发牌、伪数字
    js函数2
    js函数
    js矩形,数组,杨辉三角
  • 原文地址:https://www.cnblogs.com/gxivwshjj/p/15406044.html
Copyright © 2011-2022 走看看