如何使用C#在MS Word文本框中插入图片 [英] How to insert picture inside MS Word text box using C#

查看:187
本文介绍了如何使用C#在MS Word文本框中插入图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要通过替换像< Image>这样的单词来插入文本框或矩形的图片用这张图片写在形状里面


I have a picture that I want to insert into text box or a rectangle by replacing a word like <Image> which written inside the shape with this picture

我搜索了很多,发现这段代码替换了文档中的所有文本,包括文本在文本框和形状中:

I have searched much and found this code that replace the all text in the document including the text in the text boxes and shapes:

public void FindandReplace(Word.Document doc, string Findtext, string ReplaceText)
{
	Word.Range myStoryRange = doc.Range();

	//First search the main document using the Selection
	Word.Find myFind = myStoryRange.Find;
	myFind.Text = Findtext;
	myFind.Replacement.Text = ReplaceText;
	myFind.Forward = true;
	myFind.Wrap = Word.WdFindWrap.wdFindContinue;
	myFind.Format = false;
	myFind.MatchCase = false;
	myFind.MatchWholeWord = false;
	myFind.MatchWildcards = false;
	myFind.MatchSoundsLike = false;
	myFind.MatchAllWordForms = false;
	myFind.Execute(Replace:Word.WdReplace.wdReplaceAll);
	
	//'Now search all other stories using Ranges
	foreach(Word.Range otherStoryRange in doc.StoryRanges)
	{
		if(otherStoryRange.StoryType != Word.WdStoryType.wdMainTextStory)
		{
			Word.Find myOtherFind = otherStoryRange.Find;
			myOtherFind.Text = Findtext;
			myOtherFind.Replacement.Text = ReplaceText;
			myOtherFind.Wrap = Word.WdFindWrap.wdFindContinue;
			myOtherFind.Execute(Replace:Word.WdReplace.wdReplaceAll);
		}

		// 'Now search all next stories of other stories (doc.storyRanges dont seem to cascades in sub story)
		Word.Range nextStoryRange = otherStoryRange.NextStoryRange;
		while(nextStoryRange != null)
		{
			Word.Find myNextStoryFind = nextStoryRange.Find;
			myNextStoryFind.Text = Findtext;
			myNextStoryFind.Replacement.Text = ReplaceText;
			myNextStoryFind.Wrap = Word.WdFindWrap.wdFindContinue;
			myNextStoryFind.Execute(Replace:Word.WdReplace.wdReplaceAll);

			nextStoryRange = nextStoryRange.NextStoryRange;
		}

	}
}

我想修改此代码,以便能够替换我需要更换的文本有图片

I want to modify this code to be able to replace the text I need to replace with a picture

有什么建议吗?

提前谢谢

推荐答案

VSTO没有为此提供任何内容。我建议在
$上询问Word特定问题b $ b Word for Developers 论坛。


这篇关于如何使用C#在MS Word文本框中插入图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆