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);
  • 相关阅读:
    Java经典逻辑编程50题 (转)
    Programmingbydoing
    前端测试框架jest 简介
    puppeteer入门
    面向对象编程
    Java常识
    JS 变量
    jmeter 压力测试
    jmeter 安装
    Java 数据驱动测试
  • 原文地址:https://www.cnblogs.com/gxivwshjj/p/15406044.html
Copyright © 2011-2022 走看看