clear;clc;
%% 设置接口
%设定测试Word文件名和路径
filespec_user = [pwd '\my_template.docx'];
Word = actxserver('Word.Application');
%设置Word属性为可见
Word.Visible = 1;
Document = Word.Documents.Open(filespec_user);
Content = Document.Content; % 返回Content接口句柄
Selection = Word.Selection; % 返回Selection接口句柄
Paragraphformat = Selection.ParagraphFormat; % 返回ParagraphFormat接口句柄
%% Word替换
Selection.Find.Replacement.ClearFormatting
Selection.Find.Text = '2015';
% Selection.Find.Textbox = '2015'; %"替换Word中文本框的内容"--不能实现!
% Selection.Find.Replacement.Text = '2016';
Selection.Find.Forward =1;
Selection.Find.Wrap = 'wdFindContinue';
Selection.Find.Format =0;
Selection.Find.MatchCase = 0;
Selection.Find.MatchWholeWord = 0;
Selection.Find.MatchByte = 1;
Selection.Find.MatchWildcards = 0;
Selection.Find.MatchSoundsLike = 0;
Selection.Find.MatchAllWordForms =0;
while(Selection.Find.Execute)
Selection.Text = '2016';
Selection.Start = Selection.End;
end
%% Word中插入图片
Selection.TypeParagraph; %回车,另起一段
% I_On=dicomread('\1168352.jpg');
I_On=imread('\1168352.jpg');
H=figure();
imshow(I_On,[]);
print(H,'-dbitmap');%将图片发到剪切板
Selection=Word.Selection; %将图片粘贴到当前文档中,设置属性为嵌入式
Selection.Range.Paste;%在当前光标的位置插入图片
close; % 关闭窗口
%% Word保存和退出
Document.Save;
Word.Quit
- 1
- 2
- 3
前往页