C#如何把word的字符串替换成图片

liujiahaol12345 2013-10-08 09:52:36
设置标签有这样的问题,
1.替换多处一样的图片时,标签不能重复
2.模板客户可以修改,当添加新的位置时,就没办法插入图片,又要改程序

我是想设一个字符串,比如模板里有不定数量的picture字符,然后把这个字符都替换为相同的图片
...全文
364 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ajdkjalj 2013-11-06
  • 打赏
  • 举报
回复

        /// <summary>
        /// 替换查找到的字符串
        /// </summary>
        /// <param name="strOldText">要替换的字符</param>
        /// <param name="strNewText">要赋值的字符</param>
        /// <returns>true替换成功;false替换失败</returns>
        public bool Replace(string strOldText,string strNewText)
         {
             this.wordDoc.Content.Find.Text= strOldText;
             object FindText,  ReplaceWith, Replace ;// 
             object MissingValue = Type.Missing; 
             FindText = strOldText ;//要查找的文本
             ReplaceWith = strNewText ;//替换文本
             Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;/*wdReplaceAll - 替换找到的所有项。
                                                      * wdReplaceNone - 不替换找到的任何项。
                                                     * wdReplaceOne - 替换找到的第一项。
                                                     * */
               this.wordDoc.Content.Find.ClearFormatting();//移除Find的搜索文本和段落格式设置
               if (this.wordDoc.Content.Find.Execute(
                 ref FindText,ref MissingValue,
                 ref MissingValue,ref MissingValue,
                 ref MissingValue,ref MissingValue,
                 ref MissingValue,ref MissingValue,ref MissingValue,
                 ref ReplaceWith, ref Replace,
                 ref MissingValue,ref MissingValue,
                 ref MissingValue,ref MissingValue))
             {
                 return true ;
             }
             return false ;
             
         }
liujiahaol12345 2013-10-08
  • 打赏
  • 举报
回复
头大啊,有没有大神啊
zi_wu_xian 2013-10-08
  • 打赏
  • 举报
回复
不知道PageOffice能不能实现,楼主可以试试
liujiahaol12345 2013-10-08
  • 打赏
  • 举报
回复
我又在想,能不能定位word字符串的位置,这样我可以动态添加书签,然后添加图片,求能定位字符串位置的方法啊

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧