using System; using System.IO; using Word = Microsoft.Office.Interop.Word; namespace SavePicture { public class CreateTemplate { /// <summary> /// 替换成指定字符串 /// </summary> /// <param name="wordPath">要替换的word全路径</param> /// <param name="oldText">替换的文字</param> /// <param name="newText">替换成的文字</param> /// <returns>是否替换成功</returns> public static bool ReplaceWord(string wordPath, string oldText, string newText) { try { object nothing = System.Reflection.Missing.Value; object format = Word.WdSaveFormat.wdFormatDocument; object srcFileName = wordPath; object wrap = Word.WdFindWrap.wdFindContinue; Word.ApplicationClass appWord = new Word.ApplicationClass(); Word.Document wordDocument = appWord.Documents.Open(ref srcFileName, ref format, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing); appWord.Selection.Find.ClearFormatting(); appWord.Selection.Find.Replacement.ClearFormatting(); object objReplace = Word.WdReplace.wdReplaceAll; appWord.Selection.Find.ClearFormatting(); appWord.Selection.Find.Replacement.ClearFormatting(); appWord.Selection.Find.Text = oldText; appWord.Selection.Find.Replacement.Text = newText; appWord.Selection.Find.Execute(ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref wrap, ref nothing, ref nothing, ref objReplace, ref nothing, ref nothing, ref nothing, ref nothing); wordDocument.Save(); wordDocument.Close(); return true; } catch (Exception) { return false; } } /// <summary> /// 替换word中指定文本为图片 /// </summary> /// <param name="wordPath">word全路径</param> /// <param name="textLabel">替换字符串</param> /// <param name="imagePath">图片全路径</param> /// <returns>是否替换成功</returns> public static bool ReplaceImage(string wordPath, string textLabel, string imagePath) { try { object nothing = System.Reflection.Missing.Value; object missing = Type.Missing; object SaveWithDocument = true; object LinkToFile = false; object format = Word.WdSaveFormat.wdFormatDocument; object link = false; object confirmConversion = false; object objReplace = Word.WdReplace.wdReplaceOne; object wrap = Word.WdFindWrap.wdFindContinue; object srcFileName = wordPath; Word.ApplicationClass appWord = new Word.ApplicationClass(); Word.Document wordDocument = appWord.Documents.Open(ref srcFileName, ref format, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing); //替换图片过程 appWord.Selection.Find.ClearFormatting(); appWord.Selection.Find.Replacement.ClearFormatting(); bool found; appWord.Selection.Find.Text = textLabel; appWord.Selection.Find.Replacement.Text = ""; if (File.Exists(imagePath)) { //替换成图片 do { found = appWord.Selection.Find.Execute(ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref wrap, ref nothing, ref nothing, ref objReplace, ref nothing, ref nothing, ref nothing, ref nothing); if (found) { appWord.Selection.InlineShapes.AddPicture(imagePath, ref LinkToFile, ref SaveWithDocument, ref missing); } } while (appWord.Selection.Find.Found == true); } wordDocument.Save(); wordDocument.Close(); return true; } catch (Exception) { return false; } } } }
-
python 操作word 替换字符串为图片_用python将.docx文件中的字符串替换为jpg
2021-02-09 12:07:50在我试图用.jpg文件替换.docx文件中的字符串。首先,我将JPEG转换为BMP并将其移动到剪贴板,然后使用找到。执行用“^c”替换docx文件中的特殊字符串。在这个替换很好,但是它将一个宽度为15.42cm的图像粘贴到.docx...对不起,我的英语不好。在
我试图用.jpg文件替换.docx文件中的字符串。首先,我将JPEG转换为BMP并将其移动到剪贴板,然后使用找到。执行用“^c”替换docx文件中的特殊字符串。在
这个替换很好,但是它将一个宽度为15.42cm的图像粘贴到.docx文件中。我试着用即时消息调整大小,但它以一个大的模糊图像结束,而不是一个小图像。我怎么能把它变小?在
我用的是python2.7.2和Win7。谢谢。在from win32com.client import Dispatch
from cStringIO import StringIO
import win32clipboard
import win32com
from PIL import Image
def setImageToClipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
filepath = 'd:/tmp.jpg'
im = Image.open(filepath)
#im = im.resize((10, 10))
output = StringIO()
im.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()
w = win32com.client.Dispatch('Word.Application')
w.Visible = 1
w.DisplayAlerts = 0
doc = w.Documents.Open("d:/clipboard_test.docx")
search = "TEST"
setImageToClipboard(win32clipboard.CF_DIB, data)
w.Selection.Find.ClearFormatting()
w.Selection.Find.Replacement.ClearFormatting()
w.Selection.Find.Execute("TEST", False, True, False, False, False, True, 1, True, ReplaceWith="^c", Replace=2000)
doc.SaveAs("d:/clipboard_test2.docx")
doc.Close()
w.Quit()
-
word替换字符串为文本或图片
2012-07-20 11:05:00using System; using System.IO; using Word = Microsoft.Office.Interop.Word; namespace SavePicture { public class CreateTemplate { /// <summary>... /// 替换成指定字符...转载于:https://www.cnblogs.com/y279336671/archive/2012/07/20/2600820.html
-
Mac OS X 下 Word VBA 宏 - 如何在 Word 替换字符串
2016-12-18 17:44:26下面是一个简单的例子,用于把文档里的 ”hello" 替换成 "world" ' Define the search range to be the whole document Set myRange = ActiveDocument.Content ' Set the Find parameters myRange.Find.C下面是一个简单的例子,用于把文档里的 ”hello" 替换成 "world"
' Define the search range to be the whole document Set myRange = ActiveDocument.Content ' Set the Find parameters myRange.Find.ClearFormatting ' Loop through each match in the document Dim cached As Long cached = myRange.End Do While myRange.Find.Execute("hello") myRange.Select myRange.Text = "world" myRange.Start = myRange.Start + Len(myRange.Find.Text) myRange.End = cached Loop
参考:http://stackoverflow.com/questions/29755551/multi-dimensional-array-in-vba-for-microsoft-word-on-mac
-
word 正则表达式替换字符串
2020-03-15 10:39:09 -
C#在word文档中替换字符串
2009-04-22 00:16:00C#在word文档中替换字符串 在文档中搜索和替换字符串,先在word文档中标记字符串,然后再搜索标记字符串并用新的字符串替换标记字符串.主要是先选择整个文档,然后使用Find的Execute方法查找指定字符串并替换为相应... -
替换word文档里的字符串
2019-02-20 11:23:29可以将word文档里的字符串替换成特定的字符串 -
linuxsed替换字符串后保存_Java Word中的文本、图片替换功能
2021-01-28 13:22:57Word中的替换功能以查找指定文本然后替换为新的文本,可单个替换或全部替换。以下将要介绍的内容,除常见的以文本替换文本外,还将介绍...直接指定替换的新字符串内容)2. 获取文档内容替换文本(通过方法replace(... -
aspose word for Java 处理word 模板,替换字符串或图片
2020-01-20 14:35:28找了很久Java处理word的方法,poi 处理docx还行,处理doc就总是有各种bug,spire.doc速度有点慢,而且收费,免费版有各种限制。jacob需要依赖服务器安装Microsoft word,而且并发时会有冲突。最终找到一个相对来说好... -
PHPWord利用模板替换字符串生成精确的word文档
2016-05-11 18:29:32用phpword处理docx模板时候始终发生神奇的BUG,就是复制原版例子里的${Value1}进自己的模板然后替换是没问题的,但是只要一改动这个变量文字,PHP做相应替换就失效了。 用了下残废百度无果,一怒翻起google,准确... -
java替换word 2007字符串
2012-12-19 15:46:33新建word文档,把以下内容拷贝到里面。 [code="doc"] 工欲其善$name其器 [/code] [code="java"] package word; import java.io.FileOutputStream; import java.util.List; import... -
字符串习题1:替换字符串中所有问号
2020-11-30 10:37:47’ 字符的字符串 s,请你将所有的 ‘?’ 转换为若干小写字母,使最终的字符串不包含任何 连续重复 的字符。 解法一: class Solution: def modifyString(self, s: str) -> str: word = string.ascii_lowercase ... -
C# aspose.word 批量替换文件夹下所有word文件里的字符串代码
2018-12-04 15:14:32C# aspose.word 批量替换文件夹下所有word文件里的字符串代码,c#替换word文件最简单方法 -
Pyhon 截取,替换字符串
2020-05-15 19:48:30获取一个指定宽度居中的字符串 a = ‘hello’ print(a.center(12, ‘-’)) —hello---- 获取str再string中出现的次数 a = ‘aabbcccaatt’ print(a.count(“b”)) 2 print(a.count(“bb”)) 1 print(a.count... -
点击提交,返回一串新的字符串,新的字符串是把旧字符串中所有出现OldWord的词替换成NewWord词的字符串。
2019-10-11 08:57:58内容如下: ChgWord表 OldWord NewWord 我的 你的 中国 我国 功夫 社会 社团 -
python替换特定字符串
2017-03-16 20:49:29python 字符串替换是python操作字符串的时候经常...2用正则来替换字符串下面用个例子来实验下: a = ‘hello word’ 我把a字符串里的word替换为python 1用字符串本身的replace方法 a.replace(‘word’,’python’) -
替换字符串的最后一个字符
2018-08-19 20:42:19<p>I want it to look each word if the last char is "s" for example to replace it with "n". I am not sure which is the best way to do that. <p>I know I can grab the last char of the string with the ... -
C#如何把word的字符串替换成图片
2013-10-08 09:52:36设置标签有这样的问题, 1.替换多处一样的图片时,标签不能重复 2.模板客户可以修改,当添加新的位置时,就没办法插入...我是想设一个字符串,比如模板里有不定数量的picture字符,然后把这个字符都替换为相同的图片 -
如果字符串不是javascript中使用正则表达式的较大字符串的一部分,请替换字符串
2015-06-19 06:08:08<p>E.g.: I want to uppercase <code>OR</code> but only when not in a word like <code>befORe</code>. These words can however be written in a multitude of ways, like at the start of a line, between one ... -
poi替换字符串部分失败
2017-08-31 11:31:28poi字符串替换部分失败 public class Xwp07Test { public static void searchAndReplace(String srcPath, String destPath, Map, String> map) { try { XWPFDocument document = new ... -
逐行替换字符串变量在其他变量中包含此字符串
2014-09-16 08:44:36<p>I have <code>foreach</code> script where I would like to replace word from $variable</code> into full link from the list above: <pre><code>$variable = "church.jpg"; // use the word from $variable ... -
求正则表达式,截取替换字符串
2015-10-09 03:40:13我现在有这样一个字符串<html><head><base href="x-msg://1/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">,我想把这个给替换成空字符串,... -
JACOB替换WORD中的字符串
2012-05-24 21:21:31//查找是否存在字符串,若存在则把要查找的字符串设置好。 public static boolean find(Dispatch selection,String text) { Dispatch find=Dispatch.call(selection, "Find").toDispatch(); Dispatch.put(find... -
实现方法 replace, 能够替换字符串中的某个部分
2020-03-17 17:53:48实现方法 replace, 能够替换字符串中的某个部分 public class Test { public static void main(String[] args) { String str = "hello word"; //替换所有指定内容 System.out.println(str.replaceAll("l","-"));... -
C#读取Word模板替换相应的字符串(标签)生成新的Word
2020-03-30 18:21:00在平常工作中,生成word的方式主要是C#读取html的模板文件处理之后保存为.doc...如果我们能读取一个word模板,把模板里定义的固定字符串如{标记1}替换为想要的文字,然后生成新的word。这样生成的Word非常整洁。 ... -
用数字替换替换字符串中的数字
2013-03-30 20:00:37<p>Now i want sum the above numbers for each word and the result should be like that: <pre><code> 21 45 55 21 15 </code></pre> <p>what i tried is : <pre><code> $resultArray = explode(" ", $re); ... -
python 字符串替换
2015-12-14 13:01:24python 字符串替换 是python 操作字符串的时候...2用正则来替换字符串 下面用个例子来实验下: a = 'hello word' 把a字符串里的word替换为python 1、用字符串本身的replace方法 复制代码 代码如下: a.repl
-
Exe动态导入模型.rar
-
javascript——判断数组中是否包含某元素
-
veeam_backup_11_0_user_guide_vsphere.pdf
-
Unity iOS使用ASTC格式纹理实践
-
MHA 高可用 MySQL 架构与 Altas 读写分离
-
OracleDB数据库维护
-
Android自动化测试
-
element input-number 默认值设置为空
-
access应用的3个开发实例
-
JAVA面向对象-重写与重载的区别
-
Samba 服务配置与管理
-
MySQL你该了解的那些事【服务端篇】
-
WebOffice.rar
-
灵工云-灵活用工视频.mp4
-
【Python-随到随学】FLask第二周
-
双倍提升ApacheSpark排序性能
-
其他
-
商用密码产品主要类别及应遵循安全等级标准对照表.rar
-
linux远程
-
持续集成与单元测试xmzy.pdf